mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-13 22:44:48 +00:00
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { Body, Controller, Post, UnauthorizedException } from '@nestjs/common';
|
|
|
|
import { AuthClientService } from 'src/clients/auth/client.service';
|
|
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');
|
|
|
|
const tokens = await this.authClient
|
|
.signIn({ username, password, totp })
|
|
.then((result) => result)
|
|
.catch((err) => {
|
|
throw new UnauthorizedException(err.message);
|
|
});
|
|
|
|
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;
|
|
}
|
|
}
|