Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API 연동 관련 수정 완료 #40

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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