51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Header,
|
|
HttpCode,
|
|
Post,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { SchemaPipe } from '../common/validation.pipe';
|
|
import { AuthService } from './auth.service';
|
|
import { AuthStore } from './auth.store';
|
|
import { AuthRateGuard } from './auth-rate.guard';
|
|
import { CurrentPrincipal, Public } from './access.decorator';
|
|
import { loginSchema, type LoginInput } from './identity.schemas';
|
|
import type { Principal } from './identity.types';
|
|
|
|
@Controller('auth')
|
|
@UseGuards(AuthRateGuard)
|
|
export class AuthController {
|
|
constructor(
|
|
private readonly auth: AuthService,
|
|
private readonly store: AuthStore,
|
|
) {}
|
|
@Public()
|
|
@Post('login')
|
|
@HttpCode(200)
|
|
@Header('Cache-Control', 'no-store')
|
|
login(@Body(new SchemaPipe(loginSchema)) input: LoginInput) {
|
|
return this.auth.login(input);
|
|
}
|
|
|
|
@Get('me')
|
|
@Header('Cache-Control', 'no-store')
|
|
me(@CurrentPrincipal() principal: Principal) {
|
|
return principal;
|
|
}
|
|
|
|
@Post('logout')
|
|
@HttpCode(204)
|
|
logout(@CurrentPrincipal() principal: Principal) {
|
|
return this.store.logout(principal, false);
|
|
}
|
|
|
|
@Post('logout-all')
|
|
@HttpCode(204)
|
|
logoutAll(@CurrentPrincipal() principal: Principal) {
|
|
return this.store.logout(principal, true);
|
|
}
|
|
}
|