authentication
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Post,
|
||||
Req,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { AuthService } from './auth.service';
|
||||
import { AuthCodeDto } from 'src/model/dto';
|
||||
import { User } from 'src/model/entitites';
|
||||
import { AuthGuard } from 'src/core/guards/auth.guard';
|
||||
|
||||
@Controller('auth')
|
||||
export class AuthController {
|
||||
@@ -23,4 +27,19 @@ export class AuthController {
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Get('me')
|
||||
getMe(@Req() req: any) {
|
||||
return req.user;
|
||||
}
|
||||
|
||||
@Post('refresh')
|
||||
async getNewAccessToken(@Body() b: any) {
|
||||
if (b.refreshToken) {
|
||||
return this.authService.getNewToken(b.refreshToken);
|
||||
}
|
||||
|
||||
throw new HttpException('no token', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user