add endpoints to check if a token is valid
This commit is contained in:
@@ -16,6 +16,7 @@ import { ConfigService } from '@nestjs/config';
|
||||
import { AuthService } from './auth.service';
|
||||
import { JwtGuard } from './guards/jwt.guard';
|
||||
import { RadarScopeDto } from './dto/radarscope.dto';
|
||||
import { RadarTokenDto } from './dto/radartoken.dto';
|
||||
import { UserDto } from './dto/user.dto';
|
||||
import { Request } from 'express';
|
||||
|
||||
@@ -68,7 +69,7 @@ export class AuthController {
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'The created Bearer token to use endpoints',
|
||||
type: String,
|
||||
type: RadarTokenDto,
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 404,
|
||||
@@ -76,7 +77,7 @@ export class AuthController {
|
||||
})
|
||||
async radarScope(
|
||||
@Body('scopeData') scopeData: RadarScopeDto,
|
||||
): Promise<string> {
|
||||
): Promise<RadarTokenDto> {
|
||||
return this.authService
|
||||
.loginRadarScope(scopeData.vatsimId, scopeData.key)
|
||||
.then((token) => {
|
||||
@@ -86,10 +87,23 @@ export class AuthController {
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
return token;
|
||||
return { token };
|
||||
});
|
||||
}
|
||||
|
||||
@UseGuards(JwtGuard)
|
||||
@Get('/validate')
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'The created Bearer token to use endpoints',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 401,
|
||||
description: 'The sent Bearer token is invalid',
|
||||
})
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
validate(): void {}
|
||||
|
||||
@UseGuards(JwtGuard)
|
||||
@Get('/user')
|
||||
async user(@Req() request: Request): Promise<UserDto> {
|
||||
|
||||
11
src/auth/dto/radartoken.dto.ts
Normal file
11
src/auth/dto/radartoken.dto.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { IsNotEmpty } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class RadarTokenDto {
|
||||
@IsNotEmpty()
|
||||
@ApiProperty({
|
||||
description: 'The usable Bearer token',
|
||||
example: 'SECRET',
|
||||
})
|
||||
token: string;
|
||||
}
|
||||
Reference in New Issue
Block a user