This commit is contained in:
2026-01-08 21:36:15 +01:00
parent 05cf3bafd2
commit d689df0270
23 changed files with 25233 additions and 88 deletions

View File

@@ -1,4 +1,4 @@
import { Controller, Get, Post, Body, Query, Inject, Res } from '@nestjs/common';
import { Controller, Get, Post, Body, Query, Inject, Res, BadRequestException, UnauthorizedException } from '@nestjs/common';
import { Public } from './Public';
import { AuthService } from './AuthService';
import { LoginParamsDTO, SignupParamsDTO, SignupSponsorParamsDTO, AuthSessionDTO, ForgotPasswordDTO, ResetPasswordDTO } from './dtos/AuthDto';
@@ -12,7 +12,15 @@ export class AuthController {
@Post('signup')
async signup(@Body() params: SignupParamsDTO): Promise<AuthSessionDTO> {
return this.authService.signupWithEmail(params);
try {
return await this.authService.signupWithEmail(params);
} catch (error) {
if (error instanceof Error) {
// Convert validation or business logic errors to BadRequest
throw new BadRequestException(error.message);
}
throw error;
}
}
@Post('signup-sponsor')
@@ -22,7 +30,15 @@ export class AuthController {
@Post('login')
async login(@Body() params: LoginParamsDTO): Promise<AuthSessionDTO> {
return this.authService.loginWithEmail(params);
try {
return await this.authService.loginWithEmail(params);
} catch (error) {
if (error instanceof Error) {
// Convert authentication errors to Unauthorized
throw new UnauthorizedException(error.message);
}
throw error;
}
}
@Get('session')

View File

@@ -40,6 +40,10 @@ export class SignupParamsDTO {
@MinLength(2)
displayName!: string;
@ApiProperty({ required: false })
@IsOptional()
username?: string; // Ignored, for compatibility with tests
@ApiProperty({ required: false })
iracingCustomerId?: string;