diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index 01d7a0f..2f1407c 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -1,4 +1,3 @@ -import { HttpService } from '@nestjs/axios'; import { Controller, Get, @@ -6,12 +5,15 @@ import { HttpStatus, Query, Redirect, + Req, + UseGuards, } from '@nestjs/common'; import { ApiQuery } from '@nestjs/swagger'; import { ConfigService } from '@nestjs/config'; -import { JwtService } from '@nestjs/jwt'; -import { catchError, lastValueFrom, map } from 'rxjs'; import { AuthService } from './auth.service'; +import { JwtGuard } from './guards/jwt.guard'; +import { UserDto } from './dto/user.dto'; +import { Request } from 'express'; @Controller('auth') export class AuthController { @@ -53,4 +55,22 @@ export class AuthController { }; } } + + @UseGuards(JwtGuard) + @Get('/user') + async user(@Req() request: Request): Promise { + const token = request.headers.authorization.replace('Bearer ', ''); + return this.authService.user(token).then((user) => { + if (!user) { + throw new HttpException('Invalid user request', HttpStatus.NOT_FOUND); + } + + return { + vatsimId: user.vatsimId, + fullName: user.fullName, + administrator: user.administrator, + airportConfigurationAccess: user.airportConfigurationAccess, + }; + }); + } }