Skip to content

Commit

Permalink
fix: use all to account for unverified factors
Browse files Browse the repository at this point in the history
  • Loading branch information
J0 committed Sep 19, 2024
1 parent 1745cce commit 98e6416
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2396,7 +2396,6 @@ export default class GoTrueClient {
return { data: null, error }
}

// TODO: Remove once: https://github.com/supabase/auth/pull/1717 is deployed
if (params.factorType === 'phone') {
delete data.totp
}
Expand Down Expand Up @@ -2470,7 +2469,7 @@ export default class GoTrueClient {
// If we reach here, it means none of the conditions were met
return { data: null, error: new Error('Invalid MFA parameters') }
})
// TODO: Fix thsi hack
// TODO: Fix this hack
return result
} catch (error) {
if (isAuthError(error)) {
Expand Down Expand Up @@ -2532,12 +2531,13 @@ export default class GoTrueClient {
return { data: null, error: factorsError }
}

if (!factors || !factors.webauthn || factors.webauthn.length === 0) {
// TODO: Come back and fix thsi code
if (!factors || !factors.all || factors.all.length === 0) {
return { data: null, error: new AuthError('No WebAuthn factor found', 400, 'MFA_ERROR') }
}
const webauthnFactor = factors.all.find((factor) => factor.factor_type === 'webauthn')
if (!webauthnFactor) {
return { data: null, error: new AuthError('No WebAuthn factor found', 400, 'MFA_ERROR') }
}

const webauthnFactor = factors.webauthn[0]

const { data: challengeResponse, error: challengeError } = await this._challenge({
factorId: webauthnFactor.id,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ export interface Factor {
friendly_name?: string

/**
* Type of factor. `totp` and `phone` supported with this version
* Type of factor. `totp`, `webauthn`, and `phone` supported with this version
*/
factor_type: 'totp' | 'phone' | string
factor_type: 'totp' | 'phone' | 'webauthn' | string

/** Factor's status. */
status: 'verified' | 'unverified'
Expand Down

0 comments on commit 98e6416

Please sign in to comment.