diff options
| author | Joe Carstairs <jcarstairs@scottlogic.com> | 2024-01-22 14:59:51 +0000 |
|---|---|---|
| committer | Joe Carstairs <jcarstairs@scottlogic.com> | 2024-01-29 10:51:49 +0000 |
| commit | 19b4835bea200099bae15bc02edd5e4cafa2c46c (patch) | |
| tree | f58a0124b361c16b51a55ebe68fcf52845438270 /api/auth/_verifyRegistrationResponse.ts | |
| parent | edcb9577e28dc312f48d5ab3f5ecc8eeffd8db56 (diff) | |
verifyRegistrationResponse is single-responsibility!
Diffstat (limited to 'api/auth/_verifyRegistrationResponse.ts')
| -rw-r--r-- | api/auth/_verifyRegistrationResponse.ts | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/api/auth/_verifyRegistrationResponse.ts b/api/auth/_verifyRegistrationResponse.ts index 66af079..350bf0b 100644 --- a/api/auth/_verifyRegistrationResponse.ts +++ b/api/auth/_verifyRegistrationResponse.ts @@ -4,8 +4,6 @@ import { type RegistrationResponseJSON } from '@simplewebauthn/server/script/dep import { verifyRegistrationResponse as innerVerifyRegistrationResponse } from '@simplewebauthn/server'; import RELYING_PARTY from './_relyingParty'; -import addAuthenticator from '../db/_addAuthenticator'; -import addUser from '../db/_addUser'; import env from '../_env'; /** @@ -14,14 +12,14 @@ import env from '../_env'; * matches the expected challenge, which should be the most recent challenge * to be associated with the given user. * - * If verification is successful, saves the new user and their new - * authenticator to the database. + * If verification is successful, returns the authenticator object. Otherwise, + * returns null. */ export default async function verifyRegistrationResponse( newUser: User, expectedChallenge: string, registrationResponse: RegistrationResponseJSON, -): Promise<boolean> { +): Promise<Authenticator | null> { const verification = await innerVerifyRegistrationResponse({ response: registrationResponse, expectedChallenge, @@ -34,7 +32,7 @@ export default async function verifyRegistrationResponse( }); if (!verification.verified || !verification.registrationInfo) { - return false; + return null; } const authenticator: Authenticator = { @@ -55,8 +53,5 @@ export default async function verifyRegistrationResponse( transports: verification.registrationInfo['transports'] ?? [], }; - await addUser(newUser); - await addAuthenticator(authenticator); - - return true; + return authenticator; } |
