FEAT: add refresh token

This commit is contained in:
Arthur Simas
2022-05-09 11:47:25 -03:00
parent d7f205901b
commit 24d56c7a58
6 changed files with 73 additions and 9273 deletions
+23 -6
View File
@@ -1,18 +1,21 @@
import { Body, Controller, Post, UnauthorizedException } from '@nestjs/common';
import { AuthClientService } from 'src/clients/auth/client.service';
interface ISignIn {
username: string;
password: string;
totp: string;
}
import { ISignIn, IRefreshAccessToken } from 'src/clients/auth/interfaces';
@Controller('auth')
export class AuthController {
constructor(private authClient: AuthClientService) {}
// DEPRECADO!
@Post()
async signIn_old(@Body() body: ISignIn) {
console.log(`/auth`, 'SignIn_old');
return this.signIn(body);
}
@Post('login')
async signIn(@Body() { username, password, totp }: ISignIn) {
console.log(`/auth`, 'SignIn');
@@ -25,4 +28,18 @@ export class AuthController {
return tokens;
}
@Post('refresh-access-token')
async refreshAccessToken(@Body() { username, refreshToken }: IRefreshAccessToken) {
console.log(`/auth`, 'RefreshAccessToken');
const accessToken = await this.authClient
.refreshAccessToken({ username, refreshToken })
.then((result) => result)
.catch((err) => {
throw new UnauthorizedException(err.message);
});
return accessToken;
}
}