-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[FEAT] 로그아웃 구현 및 redis를 통한 임시 유저 저장 구현 #25
Changes from 28 commits
ceda480
7aa8289
111fcea
590a3ee
dfcf17f
2160512
1014feb
de8c777
35b4e14
d162139
34e2b77
a3143df
d416cb5
7733ab7
7cb2e29
4c35ea8
c5cceaa
af7aed3
2ba6aee
279d614
6ca8873
b53babe
615971c
0b236f1
ce84f8d
7268273
29cf1a9
8a6f2f6
747bcb5
925607e
96f0474
038848d
b040cef
7a1ab70
f9a4f43
10ffe1d
7383c5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
# 구현 내용/방법 | ||
## 📝 PR 타입 | ||
- [ ] 기능 추가 | ||
- [ ] 기능 수정 | ||
- [ ] 기능 삭제 | ||
- [ ] 리팩토링 | ||
- [ ] 의존성, 환경 변수, 빌드 관련 코드 업데이트 | ||
|
||
> 간단하게 구현한 내용과 방법에 대한 설명 | ||
> | ||
- | ||
- | ||
## 📝 반영 브랜치 | ||
<!-- feat/#issue -> dev와 같이 반영 브랜치를 표시합니다 --> | ||
<!-- closed #issue로 merge되면 issue가 자동으로 close되게 해줍니다 --> | ||
- feat/ | ||
- closed | ||
|
||
# 리뷰 필요 | ||
## 📝 변경 사항 | ||
<!-- 로그인 시, 구글 소셜 로그인 기능을 추가했습니다. 와 같이 작성합니다 --> | ||
|
||
> 나중에 다시 고민해야할 내용이 있는 내용 | ||
> | ||
> 없을 경우 작성 X | ||
|
||
> 있을 경우 작성 후 이슈 남기고 해당 PR 링크 | ||
> | ||
- | ||
- | ||
## 📝 테스트 결과 | ||
<!-- local에서 postman으로 요청한 결과를 첨부합니다, postman을 사용하지 않으면 관련 화면 캡쳐 --> | ||
|
||
close | ||
|
||
## 📝 To Reviewer | ||
<!-- review 받고 싶은 point를 작성합니다 --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
package synk.meeteam.domain.auth.api; | ||
|
||
import static synk.meeteam.domain.auth.exception.AuthExceptionType.INVALID_MAIL_REGEX; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
@@ -15,20 +14,20 @@ | |
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import synk.meeteam.domain.auth.api.dto.request.UserAuthRequestDTO; | ||
import synk.meeteam.domain.auth.api.dto.request.User#RequestDTO; | ||
import synk.meeteam.domain.auth.api.dto.response.UserAuthResponseDTO; | ||
import synk.meeteam.domain.auth.api.dto.response.UserReissueResponseDTO; | ||
import synk.meeteam.domain.auth.api.dto.response.User#ResponseDTO; | ||
import synk.meeteam.domain.auth.exception.AuthException; | ||
import synk.meeteam.domain.auth.dto.request.AuthUserRequestDto; | ||
import synk.meeteam.domain.auth.dto.request.#UserRequestDto; | ||
import synk.meeteam.domain.auth.dto.request.VerifyUserRequestDto; | ||
import synk.meeteam.domain.auth.dto.response.AuthUserResponseDto; | ||
import synk.meeteam.domain.auth.dto.response.LogoutUserResponseDto; | ||
import synk.meeteam.domain.auth.dto.response.ReissueUserResponseDto; | ||
import synk.meeteam.domain.auth.dto.response.#UserResponseDto; | ||
import synk.meeteam.domain.auth.service.AuthServiceProvider; | ||
import synk.meeteam.domain.auth.service.vo.User#VO; | ||
import synk.meeteam.domain.university.service.UniversityService; | ||
import synk.meeteam.domain.user.entity.User; | ||
import synk.meeteam.domain.user.entity.UserVO; | ||
import synk.meeteam.domain.user.entity.enums.Role; | ||
import synk.meeteam.domain.user.repository.UserRepository; | ||
import synk.meeteam.domain.user.service.UserService; | ||
import synk.meeteam.infra.mail.MailService; | ||
import synk.meeteam.infra.oauth.service.vo.enums.AuthType; | ||
|
@@ -43,7 +42,6 @@ public class AuthController { | |
private final JwtService jwtService; | ||
private final MailService mailService; | ||
private final UniversityService universityService; | ||
private final UserRepository userRepository; | ||
private final UserService userService; | ||
|
||
@Value("${spring.security.oauth2.client.naver.client-id}") | ||
|
@@ -52,57 +50,59 @@ public class AuthController { | |
private String redirectUri; | ||
|
||
@PostMapping("/social/#") | ||
public ResponseEntity<UserAuthResponseDTO> login( | ||
public ResponseEntity<AuthUserResponseDto> login( | ||
@RequestHeader(value = "authorization-code") final String authorizationCode, | ||
@RequestBody @Valid final | ||
UserAuthRequestDTO request, HttpServletResponse response) { | ||
AuthUserRequestDto requestDto) { | ||
|
||
User#VO vo = authServiceProvider.getAuthService(request.platformType()) | ||
.saveUserOrLogin(authorizationCode, request); | ||
User#VO vo = authServiceProvider.getAuthService(requestDto.platformType()) | ||
.saveUserOrLogin(authorizationCode, requestDto); | ||
|
||
if (vo.role() == Role.GUEST) { | ||
return ResponseEntity.ok(UserAuthResponseDTO | ||
return ResponseEntity.ok(AuthUserResponseDto | ||
.of(vo.platformId(), vo.authType(), vo.name(), vo.role(), null, null)); | ||
} | ||
|
||
UserAuthResponseDTO responseDTO = jwtService.issueToken(vo); | ||
if (responseDTO.authType().equals(AuthType.SIGN_UP)) { | ||
return ResponseEntity.status(HttpStatus.CREATED) | ||
.body(responseDTO); | ||
} | ||
AuthUserResponseDto responseDTO = jwtService.issueToken(vo); | ||
return ResponseEntity.ok(responseDTO); | ||
} | ||
|
||
@PostMapping("/social/sign-up") | ||
public ResponseEntity<User#ResponseDTO> #( | ||
@RequestBody @Valid User#RequestDTO requestDTO | ||
public ResponseEntity<#UserResponseDto> #( | ||
@RequestBody @Valid #UserRequestDto requestDto | ||
) { | ||
if (!universityService.isValidRegex(requestDTO.universityName(), requestDTO.email())){ | ||
throw new AuthException(INVALID_MAIL_REGEX); | ||
} | ||
Long universityId = universityService.getUniversityId(requestDto.universityName(), requestDto.departmentName(), | ||
requestDto.email()); | ||
|
||
userService.updateUniversityInfo(requestDTO); | ||
mailService.sendMail(requestDTO); | ||
authServiceProvider.getAuthService(requestDto.platformType()).updateUniversityInfo(requestDto, universityId); | ||
mailService.sendMail(requestDto, requestDto.platformId()); | ||
|
||
return ResponseEntity.ok(User#ResponseDTO.of(requestDTO.platformId())); | ||
return ResponseEntity.ok(#UserResponseDto.of(requestDto.platformId())); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 넵 emailVerify와 바꾸는게 좋을 것 같습니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 넹 좋아요 |
||
|
||
@GetMapping("/email-verify") | ||
public ResponseEntity<UserAuthResponseDTO> verify( | ||
@RequestParam String emailCode) { | ||
@PostMapping("/email-verify") | ||
public ResponseEntity<AuthUserResponseDto> verify( | ||
@RequestBody @Valid VerifyUserRequestDto requestDto) { | ||
|
||
UserVO userVO = mailService.verify(requestDto.emailCode()); | ||
User user = authServiceProvider.getAuthService(userVO.getPlatformType()) | ||
.createSocialUser(userVO, requestDto.nickName()); | ||
|
||
User user = mailService.verify(emailCode); | ||
User#VO vo = User#VO.of(user, user.getPlatformType(), user.getRole(), AuthType.SIGN_UP); | ||
UserAuthResponseDTO responseDTO = jwtService.issueToken(vo); | ||
AuthUserResponseDto responseDTO = jwtService.issueToken(vo); | ||
|
||
return ResponseEntity.status(HttpStatus.CREATED).body(responseDTO); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sign-up과 같은 맥락으로 해당 코드는 이메일 검증보다, 회원가입의 역할에 좀더 가깝다고 생각합니다. |
||
|
||
@PostMapping("/reissue") | ||
public ResponseEntity<UserReissueResponseDTO> reissue(HttpServletRequest request, | ||
HttpServletResponse response) { | ||
UserReissueResponseDTO userReissueResponseDTO = jwtService.reissueToken(request, response); | ||
return ResponseEntity.ok().body(userReissueResponseDTO); | ||
public ResponseEntity<ReissueUserResponseDto> reissue(HttpServletRequest request) { | ||
ReissueUserResponseDto reissueUserResponseDto = jwtService.reissueToken(request); | ||
return ResponseEntity.ok().body(reissueUserResponseDto); | ||
} | ||
|
||
@PostMapping("/logout") | ||
public ResponseEntity<LogoutUserResponseDto> logout(HttpServletRequest request) { | ||
return ResponseEntity.ok(jwtService.logout(request)); | ||
} | ||
Goder-0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
|
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package synk.meeteam.domain.auth.api.dto.request; | ||
package synk.meeteam.domain.auth.dto.request; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import synk.meeteam.domain.user.entity.enums.PlatformType; | ||
|
||
public record UserAuthRequestDTO(@NotNull PlatformType platformType) { | ||
public record AuthUserRequestDto(@NotNull PlatformType platformType) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package synk.meeteam.domain.auth.dto.request; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record VerifyUserRequestDto( | ||
@NotNull String emailCode, | ||
@NotNull String nickName | ||
|
||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
package synk.meeteam.domain.auth.api.dto.response; | ||
package synk.meeteam.domain.auth.dto.response; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import synk.meeteam.domain.user.entity.enums.Role; | ||
import synk.meeteam.infra.oauth.service.vo.enums.AuthType; | ||
|
||
public record UserAuthResponseDTO(@NotNull String platformId, @NotNull AuthType authType, @NotNull String userName, | ||
public record AuthUserResponseDto(@NotNull String platformId, @NotNull AuthType authType, @NotNull String userName, | ||
@NotNull Role role, String accessToken, String refreshToken) { | ||
public static UserAuthResponseDTO of(String platformId, AuthType authType, String userName, Role role, | ||
public static AuthUserResponseDto of(String platformId, AuthType authType, String userName, Role role, | ||
String accessToken, String refreshToken) { | ||
return new UserAuthResponseDTO(platformId, authType, userName, role, accessToken, refreshToken); | ||
return new AuthUserResponseDto(platformId, authType, userName, role, accessToken, refreshToken); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DTO에서 Dto로 수정하셨네요! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 음 제가 원하는건 팩토리 메서드였고, 그렇기에 record 클래스에 생성 역할을 위임하고 싶었습니다! service 로직에서 new를 사용하는 것보다 유지보수 측면에서 좋다고 생각했습니다! 혹시 생성자를 사용하는 다른 의도나 이유가 있으신가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아하! 이해했습니다. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package synk.meeteam.domain.auth.dto.response; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record LogoutUserResponseDto( | ||
@NotNull String PlatformId | ||
) { | ||
public static LogoutUserResponseDto of(String platformId) { | ||
return new LogoutUserResponseDto(platformId); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package synk.meeteam.domain.auth.dto.response; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record ReissueUserResponseDto(@NotNull String platformId, @NotNull String accessToken, @NotNull String refreshToken) { | ||
public static ReissueUserResponseDto of(String platformId, String accessToken, | ||
String refreshToken) { | ||
return new ReissueUserResponseDto(platformId, accessToken, refreshToken); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package synk.meeteam.domain.auth.dto.response; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record #UserResponseDto( | ||
@NotNull String platformId | ||
) { | ||
public static #UserResponseDto of(String platformId) { | ||
return new #UserResponseDto(platformId); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,11 +31,7 @@ public enum AuthExceptionType implements ExceptionType { | |
*/ | ||
|
||
NOT_FOUND_USER(HttpStatus.NOT_FOUND, "유효한 유저를 찾지 못했습니다."), | ||
NOT_FOUND_REFRESH_TOKEN(HttpStatus.NOT_FOUND, "유효한 리프레시 토큰을 찾지 못했습니다."), | ||
NOT_FOUND_EMAIL_CODE(HttpStatus.NOT_FOUND, "유효한 이메일 코드를 찾지 못했습니다."), | ||
NOT_FOUND_UNIVERSITY_AND_DEPARTMENT(HttpStatus.NOT_FOUND, "유효한 학교명 및 학과명을 찾지 못했습니다."); | ||
|
||
|
||
NOT_FOUND_REFRESH_TOKEN(HttpStatus.NOT_FOUND, "유효한 리프레시 토큰을 찾지 못했습니다."); | ||
Comment on lines
33
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 에러 코드의 위치를 옮기셨군요! |
||
|
||
private final HttpStatus status; | ||
private final String message; | ||
|
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.
굳굳! 좋은 것 같아요!