File tree 1 file changed +7
-3
lines changed
commit-health/src/main/java/com/example/commithealth/global/security/auth
1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 6
6
import lombok .RequiredArgsConstructor ;
7
7
import org .springframework .security .core .Authentication ;
8
8
import org .springframework .security .core .context .SecurityContextHolder ;
9
+ import org .springframework .security .core .userdetails .UsernameNotFoundException ;
9
10
import org .springframework .stereotype .Component ;
10
11
11
12
@ Component
12
13
@ RequiredArgsConstructor
13
14
public class AuthenticationFacade {
14
15
private final UserRepository repository ;
15
16
public User getCurrentUser (){
16
- Authentication authentication = SecurityContextHolder .getContext ().getAuthentication ();
17
- AuthDetails authDetails = (AuthDetails ) authentication .getPrincipal ();
18
- return repository .findByEmail (authDetails .getUsername ())
17
+ String email = SecurityContextHolder .getContext ().getAuthentication ().getName ();
18
+ return getUserByEmail (email );
19
+ }
20
+
21
+ public User getUserByEmail (String email ){
22
+ return repository .findByEmail (email )
19
23
.orElseThrow (() -> AuthNotFoundException .EXCEPTION );
20
24
}
21
25
}
You canβt perform that action at this time.
0 commit comments