@@ -15,7 +15,7 @@ import {
15
15
} from '@nestjs/common' ;
16
16
import { AuthzService } from './authz.service' ;
17
17
import { CommonService } from '../../../../libs/common/src/common.service' ;
18
- import { ApiBody , ApiOperation , ApiQuery , ApiResponse , ApiTags } from '@nestjs/swagger' ;
18
+ import { ApiBearerAuth , ApiBody , ApiOperation , ApiQuery , ApiResponse , ApiTags } from '@nestjs/swagger' ;
19
19
import { ApiResponseDto } from '../dtos/apiResponse.dto' ;
20
20
import { UserEmailVerificationDto } from '../user/dto/create-user.dto' ;
21
21
import IResponseType from '@credebl/common/interfaces/response.interface' ;
@@ -33,9 +33,9 @@ import { RefreshTokenDto } from './dtos/refresh-token.dto';
33
33
import { getDefaultClient } from '../user/utils' ;
34
34
import { ClientAliasValidationPipe } from './decorators/user-auth-client' ;
35
35
import { SessionGuard } from './guards/session.guard' ;
36
- interface SessionDetails {
37
- sessionId : string ;
38
- }
36
+ import { UserLogoutDto } from './dtos/user-logout.dto' ;
37
+ import { AuthGuard } from '@nestjs/passport' ;
38
+ import { ISessionData } from 'apps/user/interfaces/user.interface' ;
39
39
@Controller ( 'auth' )
40
40
@ApiTags ( 'auth' )
41
41
@UseFilters ( CustomExceptionFilter )
@@ -190,11 +190,7 @@ export class AuthzController {
190
190
required : false
191
191
} )
192
192
@ApiResponse ( { status : HttpStatus . OK , description : 'Success' , type : AuthTokenResponse } )
193
- async sessionDetails (
194
- @Res ( ) res : Response ,
195
- @Req ( ) req : Request ,
196
- @Query ( ) sessionId : SessionDetails
197
- ) : Promise < Response > {
193
+ async sessionDetails ( @Res ( ) res : Response , @Req ( ) req : Request , @Query ( ) sessionId : ISessionData ) : Promise < Response > {
198
194
this . logger . debug ( `in authz controller` ) ;
199
195
200
196
let sessionDetails ;
@@ -309,4 +305,30 @@ export class AuthzController {
309
305
310
306
return res . status ( HttpStatus . OK ) . json ( finalResponse ) ;
311
307
}
308
+
309
+ /**
310
+ * Log out user.
311
+ *
312
+ * @body LogoutUserDto
313
+ * @returns Logged out user from current session
314
+ */
315
+ @Post ( '/signout' )
316
+ @ApiOperation ( {
317
+ summary : 'Logout user' ,
318
+ description : 'Logout user from current session.'
319
+ } )
320
+ @ApiResponse ( { status : HttpStatus . OK , description : 'Success' , type : ApiResponseDto } )
321
+ @UseGuards ( AuthGuard ( 'jwt' ) )
322
+ @ApiBearerAuth ( )
323
+ @ApiBody ( { type : UserLogoutDto } )
324
+ async logout ( @Body ( ) logoutUserDto : UserLogoutDto , @Res ( ) res : Response ) : Promise < Response > {
325
+ await this . authzService . logout ( logoutUserDto ) ;
326
+
327
+ const finalResponse : IResponseType = {
328
+ statusCode : HttpStatus . OK ,
329
+ message : ResponseMessages . user . success . logout
330
+ } ;
331
+
332
+ return res . status ( HttpStatus . OK ) . json ( finalResponse ) ;
333
+ }
312
334
}
0 commit comments