diff options
Diffstat (limited to 'api/auth/_generateAuthenticationOptions.ts')
| -rw-r--r-- | api/auth/_generateAuthenticationOptions.ts | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/api/auth/_generateAuthenticationOptions.ts b/api/auth/_generateAuthenticationOptions.ts index 88237ac..e7d37c8 100644 --- a/api/auth/_generateAuthenticationOptions.ts +++ b/api/auth/_generateAuthenticationOptions.ts @@ -1,6 +1,7 @@ +import type User from '../types/User'; + import RELYING_PARTY from './_relyingParty'; import simplewebauthn from '@simplewebauthn/server'; -import getUser from '../db/_getUser'; import getAuthenticators from '../db/_getAuthenticators'; import setCurrentChallenge from '../db/_setCurrentChallenge'; @@ -9,22 +10,11 @@ import setCurrentChallenge from '../db/_setCurrentChallenge'; * authenticate using an authenticator which is already associated with their * account in the database. * - * If a user doesn't currently have an account, they have to create one first, - * get their account ID and register an authenticator. - * * The result should be consumed by \@simplewebauthn/browser's * `startAuthentication()` method. */ -export default async function generateAuthenticationOptions(userId: string) { - const user = await getUser(userId); - if (!user) { - return Promise.reject(` - Failed to generate authentication options because user with ID ${userId} - did not exist. - `); - } - - const userAuthenticators = await getAuthenticators(userId, ['id', 'transports', 'type']); +export default async function generateAuthenticationOptions(user: User) { + const userAuthenticators = await getAuthenticators(user.id, ['id', 'transports', 'type']); const options = await simplewebauthn.generateAuthenticationOptions({ rpID: RELYING_PARTY.id, @@ -35,7 +25,5 @@ export default async function generateAuthenticationOptions(userId: string) { userVerification: 'preferred', }); - await setCurrentChallenge(userId, options.challenge); - return options; } |
