Skip to content

Commit

Permalink
fix: nest credential options
Browse files Browse the repository at this point in the history
  • Loading branch information
J0 committed Sep 23, 2024
1 parent 2112d56 commit d0801e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
23 changes: 12 additions & 11 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2425,17 +2425,17 @@ export default class GoTrueClient {
if (!challengeData) {
return { data: null, error: new Error('Challenge data or options are null') }
}
if (
!(
challengeData.type === 'webauthn' &&
'public_key_credential_creation_options' in challengeData
)
) {
if (!(challengeData.type === 'webauthn' && challengeData?.credential_creation_options)) {
return { data: null, error: new Error('Invalid challenge data for WebAuthn') }
}
try {
const publicKeyOptions = challengeData
const publicKey = await startRegistration(publicKeyOptions)
// TODO: Undo this cast
let pubKey = challengeData?.credential_creation_options?.publicKey
console.log('after challenge data')
const publicKey = await navigator.credentials.create({
publicKey: pubKey,
})

if (!publicKey) {
return { data: null, error: new Error('Failed to create credentials') }
}
Expand Down Expand Up @@ -2610,9 +2610,10 @@ export default class GoTrueClient {

try {
// TODO: This needs to chagne since ChallengeAndVerify is also for enroll
const publicKey = await navigator.credentials.get(
challengeResponse.credential_request_options
)
const pubKey = challengeResponse?.credential_request_options?.publicKey
const publicKey = await navigator.credentials.get({
publicKey: pubKey,
})
// TODO: handle credential error
if (!publicKey) {
return { data: null, error: new AuthError('No valid credential found', 400, 'mfa_error') }
Expand Down
10 changes: 7 additions & 3 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1030,8 +1030,12 @@ export type AuthMFAChallengeResponse =

/** Timestamp in UNIX seconds when this challenge will no longer be usable. */
expires_at: number
credential_request_options?: CredentialRequestOptions
credential_creation_options?: CredentialCreationOptions
credential_request_options?: {
publicKey: PublicKeyCredentialRequestOptions
}
credential_creation_options?: {
publicKey: PublicKeyCredentialCreationOptions
}
}
error: null
}
Expand Down Expand Up @@ -1419,7 +1423,7 @@ export interface PublicKeyCredentialEntity {
}

export type AttestationConveyancePreference = 'direct' | 'enterprise' | 'indirect' | 'none'
export type AuthenticatorTransport = 'ble' | 'hybrid' | 'internal' | 'nfc' | 'usb'
export type AuthenticatorTransport = 'ble' | 'internal' | 'nfc' | 'usb'
export type COSEAlgorithmIdentifier = number
export type UserVerificationRequirement = 'discouraged' | 'preferred' | 'required'
export type AuthenticatorAttachment = 'cross-platform' | 'platform'
Expand Down

0 comments on commit d0801e3

Please sign in to comment.