-
Notifications
You must be signed in to change notification settings - Fork 1
[BE/feat] auth 도메인 1차 제작 #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…roject/WEB7_9_WY-_BE into feat/#26/create-auth-domain-mvp
…roject/WEB7_9_WY-_BE into feat/#26/create-auth-domain-mvp
…roject/WEB7_9_WY-_BE into feat/#26/create-auth-domain-mvp
| ) | ||
| public class PasswordResetToken extends BaseEntity { | ||
|
|
||
| private Long userId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nullable=false 명시해주시면 좋을 것 같습니다!
| } | ||
|
|
||
| // 최근 5분 이내 발송된 인증 코드 확인 (재발송 제한) | ||
| emailVerificationRepository.findTopByUserIdOrderByCreatedAtDesc(user.getId()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
주석은 최근 5분 이내, 코드에는 1분으로 되어있어서 통일해주시면 좋을 듯 합니다!
| } | ||
| """))) | ||
| }) | ||
| public ResponseEntity<EmailStatusResponse> getEmailStatus( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이메일 인증 상태 조회 같은 경우 다른 로직이 돌아가기 전에 인증이 되었는지 확인하는 부분이라 user entity에 emailVerify가 있으니 그게 true면 다음 작업으로 진행되고 false면 보통 errorcode로 이메일 인증을 먼저 해야합니다를 던지는 방식으로 처리했었습니다. 제가 생각하기엔 api를 불러서 확인 하는 일은 거의 없을 것 같습니다. 따로 부르게 된다면 각각 api를 불러야하니 비용이 들기도 하고요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저라면 userEntity에 isVerified() 같은 걸 넣어서 인증 여부를 boolean으로 반환해주게 할 것 같습니다.
|
|
||
| public interface RefreshTokenRepository extends JpaRepository<RefreshToken, Long> { | ||
| Optional<RefreshToken> findByToken(String token); | ||
| List<RefreshToken> findAllByUserId(Long userId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refreshToken이 여러개 있는 경우가 있나요? findAll을 써서 다 불러와야 하는지 고려해보면 좋을것 같습니다.
| // Refresh Token을 httpOnly secure 쿠키로 설정 | ||
| Cookie refreshTokenCookie = new Cookie("refreshToken", refreshToken); | ||
| refreshTokenCookie.setHttpOnly(true); | ||
| refreshTokenCookie.setSecure(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
secure이 항상 true면 http에선 안되서 로컬 개발 단계에선 쿠키가 아예 전송되지 않아 refresh가 작동하지 않을 수 있습니다! 그래서 dev와 prop 나눠서 설정하고 그런다 알고 있긴한데 잘 기억 안 나서 찾아보셔야 할 것 같아요!
| response.setHeader("Authorization", "Bearer " + accessToken); | ||
|
|
||
| // Refresh Token을 httpOnly secure 쿠키로 설정 | ||
| Cookie refreshTokenCookie = new Cookie("refreshToken", refreshToken); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
설정 중복 코드 따로 빼는 게 좋을 것 같습니다
| claims.put("userId", user.getId()); | ||
| claims.put("email", user.getEmail()); | ||
|
|
||
| String accessToken = jwtTokenProvider.createAccessToken(user.getEmail(), claims); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
생성 중복 코드 따로 빼는 게 좋을 것 같습니다
| refreshTokenRepository.save(newRefreshTokenEntity); | ||
|
|
||
| // Access Token을 Response Header에 설정 | ||
| response.setHeader("Authorization", "Bearer " + newAccessToken); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
헤더 중복 코드 따로 빼는 게 좋을 것 같습니다
| String accessToken = jwtTokenProvider.createAccessToken(user.getEmail(), claims); | ||
| String refreshToken = jwtTokenProvider.createRefreshToken(user.getEmail(), claims); | ||
|
|
||
| // Refresh Token DB 저장 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저장 중복 코드 따로 빼는 게 좋을 것 같습니다
| .orElseThrow(() -> new ServiceException(ErrorCode.INVALID_REFRESH_TOKEN)); | ||
|
|
||
| // 만료 확인 | ||
| if (refreshTokenEntity.getExpiredAt().isBefore(LocalDateTime.now())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
localDateTime 말고 duration 쓰는거 추천합니다!
| private final UserRepository userRepository; | ||
| private final PasswordEncoder passwordEncoder; | ||
|
|
||
| // 회원가입 251211 ahnbs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오타인 걸까요?
| .csrf(csrf -> csrf.disable()) // CSRF 비활성화 | ||
| .addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class) | ||
| .authorizeHttpRequests(auth -> auth | ||
| .anyRequest().permitAll() // 모든 요청 허용 (개발용) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
모든 요청에 대해 열려있어서 이 부분 하나씩 넣으셔야 할 것 같습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.anyRequest().permitAll() // 모든 요청 허용 (개발용)
여기 부분입니다
BackSeungBeom
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
확인했습니다.
hznnoy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
확인했습니다 👍
🔀 Pull Request
🏷 PR 타입(Type)
아래에서 이번 PR의 종류를 선택해주세요.
🍗 관련 이슈
📝 개요(Summary)
JWT 기반 인증 시스템 MVP 구현
🔧 코드 설명 & 변경 이유(Code Description)
주요 구현 기능
인증/인가 시스템
비밀번호 재설정
이메일 인증
기술적 결정
@AuthenticationPrincipal대신 SecurityContext 직접 조회로 의존성 감소🧪 테스트 절차(Test Plan)
🔄 API 변경 / 흐름 영향(API & Flow Impact)
신규 API 엔드포인트
POST /api/v1/auth/login- 로그인POST /api/v1/auth/logout- 로그아웃POST /api/v1/auth/refresh- 토큰 갱신POST /api/v1/auth/password/send- 비밀번호 재설정 이메일 발송POST /api/v1/auth/password/reset- 비밀번호 재설정POST /api/v1/auth/email/send- 이메일 인증 코드 발송POST /api/v1/auth/email/verify- 이메일 인증 확인GET /api/v1/auth/email- 이메일 인증 상태 조회인증 방식 변경
@AuthenticationPrincipal CustomUserDetails파라미터 주입SecurityUtil.getCurrentUserIdOrThrow()사용Swagger 문서화
👀 리뷰 포인트(Notes for Reviewer)
피드백 수정사항 정리