1- import {
2- Controller ,
3- Get ,
4- HttpCode ,
5- Logger ,
6- Param ,
7- Query ,
8- Req ,
9- Res ,
10- UseGuards ,
11- } from '@nestjs/common' ;
1+ import { Controller , Get , Param , Query , Req , Res , UseGuards } from '@nestjs/common' ;
122import { AuthService } from '../service/auth.service' ;
133import { Request , Response } from 'express' ;
14- import { HTTP_STATUS , tokenCookieOptions , JWT_TYPE } from '@constant' ;
4+ import { tokenCookieOptions , JWT_TYPE } from '@constant' ;
155import { JwtAuthGuard } from '../guard/jwt.guard' ;
166import { JwtPayload } from '@types' ;
177
@@ -20,7 +10,6 @@ export class AuthController {
2010 constructor ( private readonly authService : AuthService ) { }
2111
2212 @Get ( 'oauth/redirect/:type' )
23- @HttpCode ( HTTP_STATUS . HTTP_REDIRECT )
2413 redirectOauthPage ( @Param ( 'type' ) type : string ) {
2514 const pageUrl = this . authService . getSocialUrl ( type ) ;
2615 return { url : pageUrl } ;
@@ -32,7 +21,12 @@ export class AuthController {
3221 @Param ( 'type' ) type : string ,
3322 @Res ( ) res : Response
3423 ) {
24+ if ( ! authorizationCode ) {
25+ res . redirect ( process . env . CLIENT_ORIGIN_URL ) ;
26+ return ;
27+ }
3528 const user = await this . authService . socialStart ( { type, authorizationCode } ) ;
29+
3630 const { accessToken, refreshToken } =
3731 this . authService . createAccessTokenAndRefreshToken ( user ) ;
3832
@@ -43,12 +37,10 @@ export class AuthController {
4337
4438 @UseGuards ( JwtAuthGuard )
4539 @Get ( 'login' )
46- @HttpCode ( HTTP_STATUS . HTTP_OK )
4740 loginValidate ( @Req ( ) req : Request , @Res ( { passthrough : true } ) res : Response ) {
4841 const { accessToken, refreshToken } = req . cookies ;
4942 res . cookie ( JWT_TYPE . ACCESS_TOKEN , accessToken , tokenCookieOptions ) ;
5043 res . cookie ( JWT_TYPE . REFRESH_TOKEN , refreshToken , tokenCookieOptions ) ;
51- return { statusCode : 200 } ;
5244 }
5345
5446 @UseGuards ( JwtAuthGuard )
@@ -63,6 +55,5 @@ export class AuthController {
6355 logout ( @Res ( { passthrough : true } ) res : Response ) {
6456 res . clearCookie ( JWT_TYPE . ACCESS_TOKEN ) ;
6557 res . clearCookie ( JWT_TYPE . REFRESH_TOKEN ) ;
66- return { statusCode : 200 } ;
6758 }
6859}
0 commit comments