Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
ori0o0p committed Feb 3, 2024
1 parent d37e10d commit 3ca3d17
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.example.daemawiki.domain.auth.dto.response.TokenResponse;
import com.example.daemawiki.domain.auth.dto.request.SignupRequest;
import com.example.daemawiki.domain.auth.service.Login;
import com.example.daemawiki.domain.auth.service.Reissue;
import com.example.daemawiki.domain.auth.service.Signup;
import com.example.daemawiki.global.security.Tokenizer;
import jakarta.validation.Valid;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
Expand All @@ -17,12 +17,12 @@
public class AuthController {
private final Login loginService;
private final Signup signupService;
private final Tokenizer tokenizer;
private final Reissue reissue;

public AuthController(Login loginService, Signup signupService, Tokenizer tokenizer) {
public AuthController(Login loginService, Signup signupService, Reissue reissue) {
this.loginService = loginService;
this.signupService = signupService;
this.tokenizer = tokenizer;
this.reissue = reissue;
}

@PostMapping("/login")
Expand All @@ -38,7 +38,7 @@ public Mono<Void> signup(@Valid @RequestBody SignupRequest request) {

@PostMapping("/reissue")
public Mono<TokenResponse> reissue(@Valid @RequestBody ReissueRequest request) {
return tokenizer.reissue(request);
return reissue.execute(request);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.daemawiki.domain.auth.service;

import com.example.daemawiki.domain.auth.dto.request.ReissueRequest;
import com.example.daemawiki.domain.auth.dto.response.TokenResponse;
import com.example.daemawiki.global.security.Tokenizer;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

@Service
public class Reissue {
private final Tokenizer tokenizer;

public Reissue(Tokenizer tokenizer) {
this.tokenizer = tokenizer;
}

public Mono<TokenResponse> execute(ReissueRequest request) {
return tokenizer.reissue(request.token())
.map(token -> TokenResponse.builder()
.token(token)
.build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,18 @@ public Authentication getAuthentication(String token) {
details, null, details.getAuthorities());
}

public Mono<TokenResponse> reissue(ReissueRequest request) {
public Mono<String> reissue(String token) {
try {
Claims claims = parseClaims(request.token());
Claims claims = parseClaims(token);
String user = claims.getSubject();
String newToken = tokenize(user);

return Mono.just(TokenResponse.builder()
.token(newToken)
.build());
return Mono.justOrEmpty(newToken);
} catch (ExpiredJwtException e) {
String user = e.getClaims().getSubject();
String newToken = tokenize(user);

return Mono.just(TokenResponse.builder()
.token(newToken)
.build());
return Mono.justOrEmpty(newToken);
} catch (JwtException e) {
throw InvalidTokenException.EXCEPTION;
}
Expand Down

0 comments on commit 3ca3d17

Please sign in to comment.