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/registration.ts | |
| parent | edcb9577e28dc312f48d5ab3f5ecc8eeffd8db56 (diff) | |
verifyRegistrationResponse is single-responsibility!
Diffstat (limited to 'api/auth/registration.ts')
| -rw-r--r-- | api/auth/registration.ts | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/api/auth/registration.ts b/api/auth/registration.ts index d318d83..9f1c377 100644 --- a/api/auth/registration.ts +++ b/api/auth/registration.ts @@ -6,6 +6,9 @@ import verifyRegistrationResponse from './_verifyRegistrationResponse'; import getUser from '../db/_getUser'; import getCurrentChallenge from '../db/_getCurrentChallenge'; import setCurrentChallenge from '../db/_setCurrentChallenge'; +import { getFirstQueryParam } from '../_getFirstQueryParam'; +import addUser from 'db/_addUser'; +import addAuthenticator from 'db/_addAuthenticator'; /** * # registration @@ -152,8 +155,15 @@ async function handlePost(request: VercelRequest): Promise<(r: VercelResponse) = ); } - const isValid = await verifyRegistrationResponse(newUser, expectedChallenge, registrationResponse); + const authenticator = await verifyRegistrationResponse(newUser, expectedChallenge, registrationResponse); + const isVerified = !!authenticator; + + if (isVerified) { + await addUser(newUser); + await addAuthenticator(authenticator); + } + return (response) => void ( - response.status(200).send(isValid ? 'true' : 'false') + response.status(200).send(isVerified ? 'true' : 'false') ); } |
