Skip to content

Commit 44e56a6

Browse files
committed
refactor: rename challenge handling methods for clarity and update storage logic
1 parent 2ce581c commit 44e56a6

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
2929
return `single`;
3030
}
3131

32-
private saveChallengeToStorage(challenge: string, expiresIn?: string): void {
32+
private useChellenge(challenge: string, expiresIn?: string): void {
3333
const expiresInSeconds = expiresIn ? convertPeriodToSeconds(expiresIn) : undefined;
3434
this.options.passkeys.keyValueAdapter.set(challenge, 'stub_value', expiresInSeconds);
3535
}
3636

37-
private async checkIfChallengeInBlackList(challenge: string): Promise<boolean> {
37+
private async checkIfChellengeNotUsed(challenge: string): Promise<boolean> {
3838
const res = await this.options.passkeys.keyValueAdapter.get(challenge);
3939
if (!res) {
40-
this.saveChallengeToStorage(challenge, this.options.passkeys?.challengeValidityPeriod || '2m');
4140
return true;
4241
}
4342
return false;
@@ -50,7 +49,10 @@ export default class TwoFactorsAuthPlugin extends AdminForthPlugin {
5049
}
5150

5251
const decodedPasskeysCookies = await this.adminforth.auth.verify(passkeysCookies, 'tempLoginPasskeyChallenge', false);
53-
const isChallangeValid = await this.checkIfChallengeInBlackList(decodedPasskeysCookies.challenge);
52+
const isChallangeValid = await this.checkIfChellengeNotUsed(decodedPasskeysCookies.challenge);
53+
if (isChallangeValid) {
54+
this.useChellenge(decodedPasskeysCookies.challenge, this.options.passkeys?.challengeValidityPeriod || '2m');
55+
}
5456

5557
if (!decodedPasskeysCookies || !isChallangeValid) {
5658
return { ok: false, error: 'Invalid passkey' };

0 commit comments

Comments
 (0)