Skip to content

Commit

Permalink
refactor: 회원가입 후 access token 재발급 (#93) (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangwook02 authored Oct 10, 2023
1 parent c533184 commit 8f5d522
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@


import com.newfit.reservation.common.auth.AuthorityCheckService;
import com.newfit.reservation.common.auth.jwt.TokenProvider;
import com.newfit.reservation.domain.User;
import com.newfit.reservation.dto.request.UserSignUpRequest;
import com.newfit.reservation.dto.request.UserUpdateRequest;
import com.newfit.reservation.dto.response.UserDetailResponse;
import com.newfit.reservation.service.UserService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand All @@ -20,6 +23,7 @@ public class UserApiController {

private final UserService userService;
private final AuthorityCheckService authorityCheckService;
private final TokenProvider tokenProvider;

@PatchMapping
public ResponseEntity<Void> modify(Authentication authentication,
Expand Down Expand Up @@ -51,9 +55,12 @@ public ResponseEntity<Void> drop(Authentication authentication,

@PostMapping
public ResponseEntity<Void> signUp(@RequestHeader(value = "oauth-history-id") Long oauthHistoryId,
@Valid @RequestBody UserSignUpRequest request) {
@Valid @RequestBody UserSignUpRequest request,
HttpServletResponse response) {
// TODO: 권한 확인 로직 추가해야함. 근데 여기서 굳이 필요한 지는 모르겠음
userService.signUp(oauthHistoryId, request);
User user = userService.signUp(oauthHistoryId, request);
String accessToken = tokenProvider.generateAccessToken(user);
response.setHeader("access-token", accessToken);
return ResponseEntity
.status(CREATED)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@ public User findOneById(Long userId) {
.orElseThrow(() -> new CustomException(USER_NOT_FOUND));
}

public void signUp(Long oauthHistoryId, UserSignUpRequest request) {
public User signUp(Long oauthHistoryId, UserSignUpRequest request) {
OAuthHistory oAuthHistory = oAuthHistoryRepository
.findById(oauthHistoryId)
.orElseThrow(() -> new CustomException(OAUTH_HISTORY_NOT_FOUND));
User user = User.userSignUp(request, oAuthHistory.getProvider());
userRepository.save(user);
oAuthHistory.signUp(user);
return user;
}
}

0 comments on commit 8f5d522

Please sign in to comment.