add an endpoint to receive the user data
This commit is contained in:
@@ -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<UserDto> {
|
||||
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,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user