diff --git a/src/main/java/com/dnd/dndtravel/auth/controller/AuthTokenController.java b/src/main/java/com/dnd/dndtravel/auth/controller/AuthTokenController.java index d508762..d6f5b9f 100644 --- a/src/main/java/com/dnd/dndtravel/auth/controller/AuthTokenController.java +++ b/src/main/java/com/dnd/dndtravel/auth/controller/AuthTokenController.java @@ -2,37 +2,41 @@ import com.dnd.dndtravel.auth.apple.AppleOauthService; import com.dnd.dndtravel.auth.apple.dto.AppleUser; -import com.dnd.dndtravel.auth.domain.AuthToken; +import com.dnd.dndtravel.auth.config.JwtProvider; +import com.dnd.dndtravel.auth.repository.AuthTokenRepository; import com.dnd.dndtravel.auth.service.dto.request.AppleLoginRequest; import com.dnd.dndtravel.auth.service.dto.response.TokenResponse; -import com.dnd.dndtravel.auth.service.AuthTokenService; import com.dnd.dndtravel.member.domain.Member; import com.dnd.dndtravel.member.service.MemberService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.ResponseEntity; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -@Slf4j +import java.util.Collections; + @RequiredArgsConstructor -@RequestMapping("/api") @RestController public class AuthTokenController { - private final AuthTokenService authTokenService; - private final MemberService memberService; - private final AppleOauthService appleOauthService; + private final JwtProvider jwtProvider; + private final AuthTokenRepository authTokenRepository; @PostMapping("/login/oauth2/apple") - public ResponseEntity appleOauthLogin(@RequestBody final AppleLoginRequest appleLoginRequest) { + public TokenResponse appleOauthLogin(@RequestBody final AppleLoginRequest appleLoginRequest) { AppleUser appleUser = appleOauthService.createAppleUser(appleLoginRequest.getAppleToken()); Member member = memberService.saveMember(appleUser); - AuthToken authToken = authTokenService.issue(member); - return ResponseEntity.ok(new TokenResponse(authToken)); + + Authentication authentication = new UsernamePasswordAuthenticationToken(member.getId(), null, Collections.emptyList()); + String accessToken = jwtProvider.createToken(authentication); + String refreshToken = jwtProvider.createRefreshToken(member.getId()); + authTokenRepository.saveRefreshToken(member.getId(), refreshToken); // refreshToken은 DB에 저장 + + return new TokenResponse(accessToken); } -} +} \ No newline at end of file