feat: Enhance password reset feedback by throwing specific exceptions for non-existent users or social logins.

This commit is contained in:
pradeepkumar
2025-12-22 13:14:12 +05:30
parent f0078401ee
commit 82d342508b

View File

@@ -319,17 +319,14 @@ export class AuthService {
where: { email: dto.email.toLowerCase() },
});
// Always return success to prevent email enumeration
if (!user) {
return {
message: 'If the email exists, a password reset link will be sent',
};
throw new NotFoundException('No account found with this email address');
}
if (!user.password) {
return {
message: 'If the email exists, a password reset link will be sent',
};
throw new BadRequestException(
'This account uses social login (Google/Facebook). Please sign in with your social account.',
);
}
// Generate reset token (short-lived JWT)
@@ -350,7 +347,7 @@ export class AuthService {
});
return {
message: 'If the email exists, a password reset link will be sent',
message: 'Password reset link has been sent to your email',
};
}