authentication

This commit is contained in:
Bastian Wagner
2024-09-13 21:14:09 +02:00
parent c00aad559d
commit b4a5f04505
65 changed files with 1140 additions and 77 deletions

View File

@@ -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);
}
}