@@ -7,56 +7,67 @@ import {
77 Res ,
88 UseFilters ,
99 UseGuards ,
10- } from '@nestjs/common' ;
11- import { Response , Request } from 'express' ;
12- import { AuthService } from './auth.service' ;
13- import { Public } from './decorators/public.decorator' ;
14- import { HttpExceptionFilter } from '../utils/http-exception.filter' ;
15- import { AuthGuard } from '../common/guards/index' ;
16- import { sendResponse } from '../utils/index' ;
17- import { statusMessage } from '../constant/statusMessage' ;
10+ } from "@nestjs/common" ;
11+ import { Response , Request } from "express" ;
12+ import { AuthService } from "./auth.service" ;
13+ import { Public } from "./decorators/public.decorator" ;
14+ import { HttpExceptionFilter } from "../utils/http-exception.filter" ;
15+ import { AuthGuard } from "../common/guards/index" ;
16+ import {
17+ sendResponse ,
18+ loginSuccessResponse ,
19+ loginErrorResponse ,
20+ } from "../utils/index" ;
21+ import { statusMessage } from "../constant/statusMessage" ;
22+ import { ApiResponse } from "@nestjs/swagger" ;
1823
19- @Controller ( ' auth' )
24+ @Controller ( " auth" )
2025export class AuthController {
2126 constructor ( private authService : AuthService ) { }
2227
28+ @ApiResponse ( loginSuccessResponse )
29+ @ApiResponse ( loginErrorResponse )
2330 @Public ( )
24- @HttpCode ( HttpStatus . OK )
25- @Post ( ' login' )
31+ @UseFilters ( new HttpExceptionFilter ( ) )
32+ @Post ( " login" )
2633 async signIn ( @Body ( ) signInDto : Record < string , any > , @Res ( ) res : Response ) {
27- const token = await this . authService . signIn ( signInDto . email , signInDto . password ) ;
28- console . log ( token )
34+ const token = await this . authService . signIn (
35+ signInDto . email ,
36+ signInDto . password
37+ ) ;
38+ console . log ( token ) ;
2939
30- res . cookie ( ' access_token' , token . access_token , {
40+ res . cookie ( " access_token" , token . access_token , {
3141 httpOnly : true ,
3242 expires : new Date ( Date . now ( ) + 1 * 24 * 60 * 60 * 1000 ) ,
33- path : '/' ,
34- sameSite : ' none' ,
43+ path : "/" ,
44+ sameSite : " none" ,
3545 secure : true ,
3646 } ) ;
37-
38- res . cookie ( ' refresh_token' , token . refresh_token , {
47+
48+ res . cookie ( " refresh_token" , token . refresh_token , {
3949 httpOnly : true ,
4050 expires : new Date ( Date . now ( ) + 1 * 24 * 60 * 60 * 1000 ) ,
41- path : '/' ,
42- sameSite : ' none' ,
51+ path : "/" ,
52+ sameSite : " none" ,
4353 secure : true ,
4454 } ) ;
45- return sendResponse ( res , HttpStatus . OK , statusMessage [ HttpStatus . OK ] , true , null ) ;
55+ return sendResponse (
56+ res ,
57+ HttpStatus . OK ,
58+ statusMessage [ HttpStatus . OK ] ,
59+ true ,
60+ null
61+ ) ;
4662 }
4763
4864 // @Public ()
4965 @UseGuards ( AuthGuard )
50- @Post ( ' /refresh' )
66+ @Post ( " /refresh" )
5167 @UseFilters ( new HttpExceptionFilter ( ) )
52- async refreshTokens (
53- @Res ( ) request :Request ,
54- @Res ( ) res : Response
55- ) {
68+ async refreshTokens ( @Res ( ) request : Request , @Res ( ) res : Response ) {
5669 // console.log(request);
57- return res . sendStatus ( 200 )
70+ return res . sendStatus ( 200 ) ;
5871 // return await this.authService.refreshTokens(userId, refreshToken);
5972 }
60-
61-
6273}
0 commit comments