Skip to content

Commit

Permalink
#13 [CHORE] : Change method location
Browse files Browse the repository at this point in the history
  • Loading branch information
bbabbi committed Jun 3, 2024
1 parent 811de70 commit 29b6628
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ public void saveRefreshToken(
);
}

@Transactional
public String generateRefreshToken(Long userId) {
String refreshToken = jwtTokenProvider.issueRefreshToken(
UserAuthentication.createUserAuthentication(userId)
);
saveRefreshToken(userId, refreshToken);
return refreshToken;
}

@Transactional
public void deleteRefreshToken(
final Long userId
Expand All @@ -51,15 +60,10 @@ public Long findIdByRefreshToken(
return token.getId();
}

protected String generateAccessToken(Long userId) {
public String generateAccessToken(Long userId) {
return jwtTokenProvider.issueAccessToken(
UserAuthentication.createUserAuthentication(userId)
);
}

protected String generateRefreshToken(Long userId) {
return jwtTokenProvider.issueRefreshToken(
UserAuthentication.createUserAuthentication(userId)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


import lombok.RequiredArgsConstructor;
import org.sopt.spring.auth.redis.Service.TokenService;
import org.sopt.spring.exception.NotFoundException;
import org.sopt.spring.service.MemberService;
import org.sopt.spring.service.dto.MemberCreateDto;
import org.sopt.spring.service.dto.MemberFindDto;
Expand All @@ -26,6 +28,7 @@
public class MemberController {

private final MemberService memberService;
private final TokenService tokenService;

@PostMapping
public ResponseEntity<UserJoinResponse> postMember(
Expand All @@ -39,6 +42,15 @@ public ResponseEntity<UserJoinResponse> postMember(
);
}

@PostMapping("/members/refresh")
public ResponseEntity<UserJoinResponse> login(
@RequestHeader(name = "refreshToken") String refreshToken
) {
Long userId = tokenService.findIdByRefreshToken(refreshToken); // Refresh Token으로부터 userId 추출
String accessToken = tokenService.generateAccessToken(userId); // 새로운 Access Token 발급
return ResponseEntity.ok(new UserJoinResponse(accessToken, refreshToken, userId.toString()));
}

@GetMapping("/{memberId}")
public ResponseEntity<MemberFindDto> findMemberById(@PathVariable Long memberId) {
return ResponseEntity.ok(memberService.findMemberById(memberId));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.sopt.spring.service.dto;

public record TokenResponse (
String accessToken
) {
public static TokenResponse of(final String accessToken) {
return new TokenResponse(accessToken);
}
}

0 comments on commit 29b6628

Please sign in to comment.