Skip to content

Commit

Permalink
API 연동 관련 수정 완료 (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
limehee authored Sep 24, 2024
1 parent d3dc542 commit 4b38cad
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public interface AuthService {

String registerUser(AuthRequestDto requestDto);
TokenInfo registerUser(AuthRequestDto requestDto);

TokenInfo login(AuthRequestDto requestDto);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public class AuthController {

@Operation(summary = "회원 가입", description = "ROLE_ANONYMOUS 이상의 권한이 필요함")
@PostMapping("/api/v1/auth/register")
public ApiResponse<String> registerUser(
public ApiResponse<TokenInfo> 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 이상의 권한이 필요함<br>" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,6 +77,7 @@ public ErrorResponse<Exception> badRequestException(HttpServletResponse response
MalformedJwtException.class,
ExpiredJwtException.class,
UnsupportedJwtException.class,
UsernameNotFoundException.class
})
public ApiResponse<Void> unAuthorizeException(HttpServletResponse response, Exception e) {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
Expand Down

0 comments on commit 4b38cad

Please sign in to comment.