1- import { Controller , Get , HttpStatus , Query , Res } from '@nestjs/common' ;
1+ import {
2+ Body ,
3+ Controller ,
4+ Get ,
5+ HttpStatus ,
6+ Post ,
7+ Query ,
8+ Res ,
9+ } from '@nestjs/common' ;
210import { AuthService } from './auth.service' ;
311import { Response } from 'express' ;
4- import { ApiOperation , ApiTags } from '@nestjs/swagger' ;
12+ import { ApiBody , ApiOperation , ApiTags } from '@nestjs/swagger' ;
513
614@ApiTags ( 'Auth' )
715@Controller ( 'auth' )
816export class AuthController {
917 constructor ( private readonly authService : AuthService ) { }
1018
19+ @ApiOperation ( {
20+ summary : 'kakao login with accessToken from front' ,
21+ description :
22+ '(only for staging server)kakao accessToken을 입력하면 cafe-search 서비스의 accessToken을 반환합니다.' ,
23+ } )
24+ @ApiBody ( {
25+ schema : {
26+ type : 'object' ,
27+ properties : {
28+ accessToken : {
29+ type : 'string' ,
30+ description : 'Kakao access token' ,
31+ example : 'your-kakao-access-token' ,
32+ } ,
33+ } ,
34+ } ,
35+ } )
36+ @Post ( 'kakao/signin' )
37+ async kakaoLoginWithAccessToken (
38+ @Body ( 'accessToken' ) accessToken : string ,
39+ @Res ( ) res : Response ,
40+ ) {
41+ try {
42+ const jwtToken =
43+ await this . authService . kakaoLoginWithAccessToken ( accessToken ) ;
44+
45+ return res . status ( HttpStatus . OK ) . json ( {
46+ message : 'Kakao Login Success' ,
47+ token : jwtToken ,
48+ } ) ;
49+ } catch ( error ) {
50+ return res . status ( HttpStatus . INTERNAL_SERVER_ERROR ) . json ( {
51+ message : 'Kakao Login Failed' ,
52+ error : error . message ,
53+ } ) ;
54+ }
55+ }
56+
1157 @ApiOperation ( {
1258 summary : 'redirect to kakao login page' ,
1359 description : 'API 요청 시 카카오 로그인 페이지로 리다이렉트됩니다.' ,
1460 } )
15- @Get ( 'kakao' )
16- async kakaoLogin ( @Res ( ) res : Response ) {
61+ @Get ( 'kakao/login ' )
62+ async getKakaoLoginUri ( @Res ( ) res : Response ) {
1763 const kakaoAuthUrl = this . authService . getKakaoAuthUrl ( ) ;
1864
1965 return res . redirect ( kakaoAuthUrl ) ;
@@ -22,7 +68,7 @@ export class AuthController {
2268 @ApiOperation ( {
2369 summary : 'callback api for kakao login' ,
2470 description :
25- 'kakao login page에 로그인 후 받은 authorization code와 함께 API 요청 시 access_token을 반환합니다.' ,
71+ '(only for staging server) kakao login page에 로그인 후 받은 authorization code와 함께 API 요청 시 access_token을 반환합니다.' ,
2672 } )
2773 @Get ( 'kakao/callback' )
2874 async kakaoLoginCallback ( @Query ( 'code' ) code : string , @Res ( ) res : Response ) {
0 commit comments