feat: add mode parameter to social auth to distinguish between login and signup flows
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user