diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index cae99d6..bbc28ff 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -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 { + ): Promise { 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 { diff --git a/src/auth/dto/radartoken.dto.ts b/src/auth/dto/radartoken.dto.ts new file mode 100644 index 0000000..4ec5166 --- /dev/null +++ b/src/auth/dto/radartoken.dto.ts @@ -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; +}