Skip to content

Commit 3c994eb

Browse files
authored
Add endpoint for SSR validation (#82)
1 parent 6b16065 commit 3c994eb

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

backend/gateway-service/src/modules/auth/auth.controller.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
Query,
88
Res,
99
UseGuards,
10+
Headers,
11+
BadRequestException
1012
} from '@nestjs/common';
1113
import { Response } from 'express';
1214
import {
@@ -89,6 +91,21 @@ export class AuthController {
8991
);
9092
}
9193

94+
// Strictly for SSR
95+
@Public()
96+
@Post('validate-token')
97+
@ApiOkResponse({ description: 'Token is valid' })
98+
@ApiBadRequestResponse({ description: 'Token is invalid' })
99+
async validateToken(@Headers('authorization') authHeader: string): Promise<boolean> {
100+
const [bearer, token] = authHeader?.split(' ');
101+
102+
if (!(bearer === 'Bearer') || !token) {
103+
throw new BadRequestException('Token not provided');
104+
}
105+
106+
return await firstValueFrom(this.authClient.send({ cmd: 'validate-access-token' }, token));
107+
}
108+
92109
@Post('logout')
93110
@ApiBearerAuth('access-token')
94111
@ApiOkResponse({ description: 'User logged out successfully' })

0 commit comments

Comments
 (0)