Skip to content

Commit

Permalink
Merge pull request #56 from YAPP-Github/feature/PC-582-logout
Browse files Browse the repository at this point in the history
[PC-582] 로그아웃 기능 구현
  • Loading branch information
Lujaec authored Feb 15, 2025
2 parents 0bc6e32 + b802d40 commit 7b9cbf7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.yapp.domain.auth.application.oauth.service;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.yapp.core.auth.token.RefreshTokenService;

@Service
@RequiredArgsConstructor
public class LogoutService {

private final RefreshTokenService refreshTokenService;

public void logout(Long userId) {
refreshTokenService.deleteRefreshToken(userId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.yapp.domain.auth.presentation;

import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yapp.domain.auth.application.oauth.service.LogoutService;
import org.yapp.format.CommonResponse;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/logout")
public class LogoutController {

private final LogoutService logoutService;

@PatchMapping
public ResponseEntity<CommonResponse<Void>> logout(@AuthenticationPrincipal Long userId) {
logoutService.logout(userId);
return ResponseEntity.ok(CommonResponse.createSuccessWithNoContent());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public void saveRefreshToken(Long userId, String refreshToken) {
refreshTokenRepository.save(new RefreshToken(userId, refreshToken));
}

@Transactional
public void deleteRefreshToken(Long userId) {
refreshTokenRepository.deleteById(userId);
}

private void validateRefreshToken(String givenRefreshToken, String expectedRefreshToken) {
try {
jwtUtil.isExpired(givenRefreshToken);
Expand Down

0 comments on commit 7b9cbf7

Please sign in to comment.