added userId in the token
This commit is contained in:
@@ -19,7 +19,6 @@ import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@@ -33,9 +32,6 @@ public class AuthenticationService {
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
@Autowired
|
||||
private RoleDao roleDao;
|
||||
|
||||
@@ -51,13 +47,13 @@ public class AuthenticationService {
|
||||
Authentication authentication = this.authenticationManager.authenticate(authenticationToken);
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
log.info("Authentication successful for email: {}", loginReq.getEmail());
|
||||
String token = tokenProvider.createToken(authentication, loginReq.getRememberMe());
|
||||
log.info("JWT token generated for email: {}", loginReq.getEmail());
|
||||
UserEntity user = userRepository.findByEmail(loginReq.getEmail());
|
||||
if (user == null) {
|
||||
log.error("User not found for email: {}", loginReq.getEmail());
|
||||
throw new CustomValidationException(Status.NOT_FOUND, Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG));
|
||||
}
|
||||
String token = tokenProvider.createToken(authentication, loginReq.getRememberMe(), user);
|
||||
log.info("JWT token generated for email: {}", loginReq.getEmail());
|
||||
RoleResponseBean roleResponseBean = roleDao.convertRoleEntityToRoleResponse(user.getRoleEntity());
|
||||
JWTToken jwtToken = new JWTToken(token, new LoginResponse(user.getId(), user.getEmail(), user.getFirstName(),
|
||||
user.getLastName(), roleResponseBean, user.getPhoneNumber(), user.getAddress(), user.getOrganization(),
|
||||
|
||||
Reference in New Issue
Block a user