diff --git a/src/main/java/com/stempo/api/domain/application/service/AuthService.java b/src/main/java/com/stempo/api/domain/application/service/AuthService.java index 47583d6..b02ea11 100644 --- a/src/main/java/com/stempo/api/domain/application/service/AuthService.java +++ b/src/main/java/com/stempo/api/domain/application/service/AuthService.java @@ -6,7 +6,7 @@ public interface AuthService { - String registerUser(AuthRequestDto requestDto); + TokenInfo registerUser(AuthRequestDto requestDto); TokenInfo login(AuthRequestDto requestDto); diff --git a/src/main/java/com/stempo/api/domain/application/service/AuthServiceImpl.java b/src/main/java/com/stempo/api/domain/application/service/AuthServiceImpl.java index de20ea3..ff2d49a 100644 --- a/src/main/java/com/stempo/api/domain/application/service/AuthServiceImpl.java +++ b/src/main/java/com/stempo/api/domain/application/service/AuthServiceImpl.java @@ -27,7 +27,7 @@ public class AuthServiceImpl implements AuthService { private final PasswordEncoder passwordEncoder; @Override - public String registerUser(AuthRequestDto requestDto) { + public TokenInfo registerUser(AuthRequestDto requestDto) { String deviceTag = requestDto.getDeviceTag(); String password = requestDto.getPassword(); @@ -37,7 +37,8 @@ public String registerUser(AuthRequestDto requestDto) { String finalPassword = StringUtils.isEmpty(password) ? null : passwordEncoder.encode(password); User user = User.create(deviceTag, finalPassword); - return userService.save(user).getDeviceTag(); + userService.save(user); + return jwtTokenProvider.generateToken(user.getDeviceTag(), user.getRole()); } @Override diff --git a/src/main/java/com/stempo/api/domain/presentation/AuthController.java b/src/main/java/com/stempo/api/domain/presentation/AuthController.java index 86b217d..12a6b4b 100644 --- a/src/main/java/com/stempo/api/domain/presentation/AuthController.java +++ b/src/main/java/com/stempo/api/domain/presentation/AuthController.java @@ -23,11 +23,11 @@ public class AuthController { @Operation(summary = "회원 가입", description = "ROLE_ANONYMOUS 이상의 권한이 필요함") @PostMapping("/api/v1/auth/register") - public ApiResponse registerUser( + public ApiResponse registerUser( @Valid @RequestBody AuthRequestDto requestDto ) { - String deviceTag = authService.registerUser(requestDto); - return ApiResponse.success(deviceTag); + TokenInfo token = authService.registerUser(requestDto); + return ApiResponse.success(token); } @Operation(summary = "로그인", description = "ROLE_ANONYMOUS 이상의 권한이 필요함
" + diff --git a/src/main/java/com/stempo/api/global/handler/GlobalExceptionHandler.java b/src/main/java/com/stempo/api/global/handler/GlobalExceptionHandler.java index 37ced90..de4b9ac 100644 --- a/src/main/java/com/stempo/api/global/handler/GlobalExceptionHandler.java +++ b/src/main/java/com/stempo/api/global/handler/GlobalExceptionHandler.java @@ -30,6 +30,7 @@ import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.transaction.TransactionSystemException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MissingServletRequestParameterException; @@ -76,6 +77,7 @@ public ErrorResponse badRequestException(HttpServletResponse response MalformedJwtException.class, ExpiredJwtException.class, UnsupportedJwtException.class, + UsernameNotFoundException.class }) public ApiResponse unAuthorizeException(HttpServletResponse response, Exception e) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);