Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
J0 committed Jul 25, 2024
1 parent 29fc62c commit fe2a594
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 19 deletions.
47 changes: 31 additions & 16 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2340,26 +2340,41 @@ export default class GoTrueClient {
if (sessionError) {
return { data: null, error: sessionError }
}
if (params.factorType === 'webauthn') {
const { data, error } = await _request(this.fetch, 'POST', `${this.url}/factors`, {
body: {
friendly_name: params.friendlyName,
factor_type: params.factorType,
// phone_number: params.phoneNumber,
},
headers: this.headers,
jwt: sessionData?.session?.access_token,
})
if (error) {
return { data: null, error }
}
return { data, error: null }
} else {
const { data, error } = await _request(this.fetch, 'POST', `${this.url}/factors`, {
body: {
friendly_name: params.friendlyName,
factor_type: params.factorType,
issuer: params.issuer,
},
headers: this.headers,
jwt: sessionData?.session?.access_token,
})

const { data, error } = await _request(this.fetch, 'POST', `${this.url}/factors`, {
body: {
friendly_name: params.friendlyName,
factor_type: params.factorType,
issuer: params.issuer,
},
headers: this.headers,
jwt: sessionData?.session?.access_token,
})
if (error) {
return { data: null, error }
}

if (error) {
return { data: null, error }
}
if (data?.totp?.qr_code) {
data.totp.qr_code = `data:image/svg+xml;utf-8,${data.totp.qr_code}`
}

if (data?.totp?.qr_code) {
data.totp.qr_code = `data:image/svg+xml;utf-8,${data.totp.qr_code}`
return { data, error: null }
}

return { data, error: null }
})
} catch (error) {
if (isAuthError(error)) {
Expand Down
22 changes: 19 additions & 3 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ export type GenerateLinkType =

export type MFAEnrollParams = {
/** The type of factor being enrolled. */
factorType: 'totp'
factorType: 'totp' | 'webauthn'
/** Domain which the user is enrolled with. */
issuer?: string
/** Human readable name assigned to the factor. */
Expand Down Expand Up @@ -873,8 +873,8 @@ export type AuthMFAEnrollResponse =
/** ID of the factor that was just enrolled (in an unverified state). */
id: string

/** Type of MFA factor. Only `totp` supported for now. */
type: 'totp'
/** Type of MFA factor. `totp` and `webauhthn` supported for now. */
type: 'totp' | 'webauthn'

/** TOTP enrollment information. */
totp: {
Expand All @@ -897,6 +897,14 @@ export type AuthMFAEnrollResponse =
}
error: null
}
| {
data: {
public_key_credential_request_options: Object
factor_id: string
challenge_id: string
}
error: null
}
| {
data: null
error: AuthError
Expand All @@ -923,6 +931,14 @@ export type AuthMFAChallengeResponse =
}
error: null
}
| {
data: {
// TODO: Get this from simplewebauthn types
public_key_credential_request_options: Object
id: string
}
error: null
}
| { data: null; error: AuthError }

export type AuthMFAListFactorsResponse =
Expand Down

0 comments on commit fe2a594

Please sign in to comment.