Skip to content

Commit

Permalink
fix: principal 처리 로직 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
dong2ast committed Jul 13, 2023
1 parent 6099874 commit 1e0283e
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/main/java/org/sophy/sophy/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -68,8 +66,7 @@ public TokenDto login(MemberLoginRequestDto memberLoginRequestDto) {
// 3. 인증 정보를 기반으로 JWT 토큰 생성
TokenDto tokenDto = tokenProvider.generateTokenDto(authentication, memberLoginRequestDto.getAccessTokenExpiredTime(), memberLoginRequestDto.getRefreshTokenExpiredTime());

Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Member member = memberRepository.findByEmail(((UserDetails) principal).getUsername()).orElseThrow(() -> new UsernameNotFoundException("사용자를 데이터베이스에서 찾을 수 없습니다."));
Member member = memberRepository.findByEmail(authentication.getName()).orElseThrow(() -> new UsernameNotFoundException("사용자를 데이터베이스에서 찾을 수 없습니다."));
tokenDto.setMemberId(member.getId());

// 4. RefreshToken 저장
Expand Down

0 comments on commit 1e0283e

Please sign in to comment.