Skip to content

Commit

Permalink
fix: remove unneeded imports
Browse files Browse the repository at this point in the history
  • Loading branch information
J0 committed Sep 30, 2024
1 parent a604c52 commit 7159833
Showing 1 changed file with 40 additions and 45 deletions.
85 changes: 40 additions & 45 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import { localStorageAdapter, memoryLocalStorageAdapter } from './lib/local-stor
import { polyfillGlobalThis } from './lib/polyfills'
import { version } from './lib/version'
import { LockAcquireTimeoutError, navigatorLock } from './lib/locks'
import { startRegistration } from '@simplewebauthn/browser'

import type {
AuthChangeEvent,
Expand Down Expand Up @@ -2809,63 +2808,59 @@ export default class GoTrueClient {
private async _challengeAndVerify(
params: MFAChallengeAndVerifyParams
): Promise<AuthMFAVerifyResponse> {
if ('factorId' in params && 'code' in params) {
const { data: challengeResponse, error: challengeError } = await this._challenge({
factorId: params.factorId,
})
if (challengeError) {
return { data: null, error: challengeError }
if (!('factorId' in params && 'code' in params)) {
return {
data: null,
error: new AuthError('Invalid parameters', 400, 'invalid_parameters'),
}
return await this._verify({
factorId: params.factorId,
challengeId: challengeResponse.id,
code: params.code,
})
}
return {
data: null,
error: new AuthError('Unknown error', 500, 'unknown_error'),
const { factorId, code } = params
const { data: challengeResponse, error: challengeError } = await this._challenge({
factorId: params.factorId,
})
if (challengeError) {
return { data: null, error: challengeError }
}
return await this._verify({
factorId: params.factorId,
challengeId: challengeResponse.id,
code: params.code,
})
}

/**
* {@see GoTrueMFAApi#listFactors}
*/
private async _listFactors(): Promise<AuthMFAListFactorsResponse> {
// use #getUser instead of #_getUser as the former acquires a lock
try {
const {
data: { user },
error: userError,
} = await this.getUser()
if (userError) {
return { data: null, error: userError }
}
const {
data: { user },
error: userError,
} = await this.getUser()
if (userError) {
return { data: null, error: userError }
}

const factors = user?.factors || []
const totp = factors.filter(
(factor) => factor.factor_type === 'totp' && factor.status === 'verified'
)
const phone = factors.filter(
(factor) => factor.factor_type === 'phone' && factor.status === 'verified'
)
const factors = user?.factors || []
const totp = factors.filter(
(factor) => factor.factor_type === 'totp' && factor.status === 'verified'
)
const phone = factors.filter(
(factor) => factor.factor_type === 'phone' && factor.status === 'verified'
)

const webauthn = factors.filter(
(factor) => factor.factor_type === 'webauthn' && factor.status === 'verified'
)
const webauthn = factors.filter(
(factor) => factor.factor_type === 'webauthn' && factor.status === 'verified'
)

return {
data: {
all: factors,
totp,
phone,
webauthn,
},
error: null,
}
} catch (error) {
console.error('Error in _listFactors:', error)
return { data: null, error: new AuthError('Failed to list factors') }
return {
data: {
all: factors,
totp,
phone,
webauthn,
},
error: null,
}
}

Expand Down

0 comments on commit 7159833

Please sign in to comment.