Skip to content

Commit 63d1361

Browse files
fix: simplify credentials provider authorization flow (#25563)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent cbcd769 commit 63d1361

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

packages/features/auth/lib/next-auth-options.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,21 +169,15 @@ const providers: Provider[] = [
169169
identifier: hashEmail(user.email),
170170
});
171171

172-
if (!user.password?.hash && user.identityProvider !== IdentityProvider.CAL && !credentials.totpCode) {
173-
throw new Error(ErrorCode.IncorrectEmailPassword);
174-
}
175-
if (!user.password?.hash && user.identityProvider == IdentityProvider.CAL) {
172+
// Users without a password must use their identity provider (Google/SAML) to login
173+
if (!user.password?.hash) {
176174
throw new Error(ErrorCode.IncorrectEmailPassword);
177175
}
178176

179-
if (user.password?.hash && !credentials.totpCode) {
180-
if (!user.password?.hash) {
181-
throw new Error(ErrorCode.IncorrectEmailPassword);
182-
}
183-
const isCorrectPassword = await verifyPassword(credentials.password, user.password.hash);
184-
if (!isCorrectPassword) {
185-
throw new Error(ErrorCode.IncorrectEmailPassword);
186-
}
177+
// Always verify password for users who have one
178+
const isCorrectPassword = await verifyPassword(credentials.password, user.password.hash);
179+
if (!isCorrectPassword) {
180+
throw new Error(ErrorCode.IncorrectEmailPassword);
187181
}
188182

189183
if (user.twoFactorEnabled && credentials.backupCode) {

0 commit comments

Comments
 (0)