You can retrieve the user details from the authentication object instead of making another call to the database:
Authentication authentication = authenticationManager.authenticate(
new UsernamePasswordAuthenticationToken(
request.getUsernameOrEmail(),
request.getPassword()
)
);
var user = (User) authentication.getPrincipal();
var jwtToken = jwtService.generateJwt(user);
You can retrieve the user details from the authentication object instead of making another call to the database: