Skip to content

Commit 34226e3

Browse files
committed
fix(DEV-1366): Keep passkey challenge on failed verification for retry
1 parent d3a2115 commit 34226e3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/core/modules/better-auth/core-better-auth-api.middleware.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable, Logger, NestMiddleware, Optional } from '@nestjs/common';
1+
import { Injectable, NestMiddleware, Optional } from '@nestjs/common';
22
import { NextFunction, Request, Response } from 'express';
33

44
import { isProduction } from '../../common/helpers/logging.helper';
@@ -244,9 +244,12 @@ export class CoreBetterAuthApiMiddleware implements NestMiddleware {
244244
}
245245
}
246246

247-
// Clean up the used challenge mapping after verification (success or failure)
248-
if (challengeIdToDelete && this.challengeService) {
247+
// Clean up the used challenge mapping only after SUCCESSFUL verification
248+
// On failure, keep the challenge so the user can retry with a different passkey
249+
if (challengeIdToDelete && this.challengeService && response.ok) {
249250
await this.challengeService.deleteChallengeMapping(challengeIdToDelete);
251+
} else if (challengeIdToDelete && !response.ok) {
252+
this.logger.debug(`Keeping challenge mapping after failed verification (status=${response.status}) for retry`);
250253
}
251254

252255
// Convert Web Standard Response to Express response using shared helper

0 commit comments

Comments
 (0)