ali-bouali / spring-boot-3-jwt-security

Sample project on how to implement JWT security based using Spring boot 3 and Spring security 6

Home Page:https://aliboucoding.com/p/securing-your-spring-boot-3-0-applications-with-json-web-tokens-jwt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AuthenticationService.java line 43 - Double call to the database

opened this issue · comments

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);
commented

Thank you! I also jsut discovered this.

yes that's true.
As I mentioned, it is just a sample project to show how to implement JWT security with Spring boot