diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 8f8e741..cf7c415 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -256,8 +256,13 @@ export class AuthService { where: { id: user.id }, data: { [providerIdField]: dto.providerId }, }); + } else if (dto.mode === 'login') { + // Login mode: user must exist + throw new BadRequestException( + 'No account found with this email. Please sign up first.', + ); } else { - // Create new user + // Create new user (signup mode) const role = dto.role === 'AGENT' ? UserRole.AGENT : UserRole.USER; const authProvider = dto.provider === 'google' diff --git a/src/auth/dto/social-auth.dto.ts b/src/auth/dto/social-auth.dto.ts index 4e14cdf..97a8637 100644 --- a/src/auth/dto/social-auth.dto.ts +++ b/src/auth/dto/social-auth.dto.ts @@ -65,4 +65,14 @@ export class SocialAuthDto { @IsOptional() @IsString() agentTypeId?: string; + + @ApiPropertyOptional({ + example: 'login', + description: 'Auth mode: login (existing users only) or signup (create if needed)', + enum: ['login', 'signup'], + default: 'signup', + }) + @IsOptional() + @IsEnum(['login', 'signup'], { message: 'Mode must be login or signup' }) + mode?: 'login' | 'signup'; } diff --git a/src/users/users.service.ts b/src/users/users.service.ts index f2a3d89..39de069 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -487,15 +487,6 @@ export class UsersService { throw new BadRequestException('Profile is already verified'); } - // Validate required fields are filled - const missingFields = await this.getRequiredFieldsMissing(user.agentProfile.id, user.agentProfile.agentTypeId); - if (missingFields.length > 0) { - throw new BadRequestException({ - message: 'Please fill in all required fields before submitting', - missingFields, - }); - } - // Capture snapshot of current profile data + documents const profileSnapshot = await this.captureProfileSnapshot(user.agentProfile.id);