Skip to content

Commit

Permalink
[refactor] 토큰 재발급 로직 변경 #62
Browse files Browse the repository at this point in the history
[refactor] 토큰 재발급 로직 변경
  • Loading branch information
yangchef1 authored Jun 28, 2024
2 parents 6b27104 + 596207c commit 8c6c073
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
package com.sanbosillok.sanbosillokserver.api.auth.controller;

import com.sanbosillok.sanbosillokserver.api.auth.dto.AccessTokenResponse;
import com.sanbosillok.sanbosillokserver.api.auth.dto.RefreshTokenRequest;
import com.sanbosillok.sanbosillokserver.api.auth.dto.ReissueTokenResponse;
import com.sanbosillok.sanbosillokserver.api.auth.service.TokenService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/token")
public class TokenController {
private final TokenService tokenService;

@GetMapping("/refresh")
public AccessTokenResponse getNewToken(@RequestBody @Valid RefreshTokenRequest refreshTokenRequest) {
@PostMapping("/refresh")
public ReissueTokenResponse getNewToken(@RequestBody @Valid RefreshTokenRequest refreshTokenRequest) {
return tokenService.reIssueAccessToken(refreshTokenRequest.getRefreshToken());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

@Data
@AllArgsConstructor
public class AccessTokenResponse {
public class ReissueTokenResponse {
private String accessToken;
private String refreshToken;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.sanbosillok.sanbosillokserver.api.auth.service;

import com.sanbosillok.sanbosillokserver.api.auth.dto.AccessTokenResponse;
import com.sanbosillok.sanbosillokserver.api.auth.dto.ReissueTokenResponse;
import com.sanbosillok.sanbosillokserver.api.member.domain.Member;
import com.sanbosillok.sanbosillokserver.api.member.repository.MemberRepository;
import com.sanbosillok.sanbosillokserver.config.jwt.JwtTokenProvider;
Expand All @@ -13,7 +13,7 @@ public class TokenService {
private final JwtTokenProvider jwtTokenProvider;
private final MemberRepository memberRepository;

public AccessTokenResponse reIssueAccessToken(String refreshToken) {
public ReissueTokenResponse reIssueAccessToken(String refreshToken) {

if (refreshToken == null) {
throw new IllegalArgumentException("토큰이 비어있습니다.");
Expand All @@ -28,7 +28,8 @@ public AccessTokenResponse reIssueAccessToken(String refreshToken) {

String username = member.getUsername();
String role = member.getRole().toString();
Long id = member.getId();

return new AccessTokenResponse(jwtTokenProvider.createAccessToken(username, role));
return new ReissueTokenResponse(jwtTokenProvider.createAccessToken(username, role), jwtTokenProvider.createRefreshToken(id));
}
}

0 comments on commit 8c6c073

Please sign in to comment.