30 lines
899 B
TypeScript
30 lines
899 B
TypeScript
import { Controller, Get, Post, Body } from '@nestjs/common';
|
|
import { AuthService } from './AuthService';
|
|
import { LoginParams, SignupParams, AuthSessionDTO } from './dtos/AuthDto';
|
|
import type { CommandResultDTO } from './presenters/CommandResultPresenter';
|
|
|
|
@Controller('auth')
|
|
export class AuthController {
|
|
constructor(private readonly authService: AuthService) {}
|
|
|
|
@Post('signup')
|
|
async signup(@Body() params: SignupParams): Promise<AuthSessionDTO> {
|
|
return this.authService.signupWithEmail(params);
|
|
}
|
|
|
|
@Post('login')
|
|
async login(@Body() params: LoginParams): Promise<AuthSessionDTO> {
|
|
return this.authService.loginWithEmail(params);
|
|
}
|
|
|
|
@Get('session')
|
|
async getSession(): Promise<AuthSessionDTO | null> {
|
|
return this.authService.getCurrentSession();
|
|
}
|
|
|
|
@Post('logout')
|
|
async logout(): Promise<CommandResultDTO> {
|
|
return this.authService.logout();
|
|
}
|
|
}
|