Skip to content

Commit c7f94ff

Browse files
committed
πŸ”„ :: λ©”μ†Œλ“œ 2개둜 λ³€κ²½
1 parent 55b387d commit c7f94ff

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

β€Žcommit-health/src/main/java/com/example/commithealth/global/security/auth/AuthenticationFacade.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@
66
import lombok.RequiredArgsConstructor;
77
import org.springframework.security.core.Authentication;
88
import org.springframework.security.core.context.SecurityContextHolder;
9+
import org.springframework.security.core.userdetails.UsernameNotFoundException;
910
import org.springframework.stereotype.Component;
1011

1112
@Component
1213
@RequiredArgsConstructor
1314
public class AuthenticationFacade {
1415
private final UserRepository repository;
1516
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)
1923
.orElseThrow(() -> AuthNotFoundException.EXCEPTION);
2024
}
2125
}

0 commit comments

Comments
Β (0)