Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions packages/web-core/src/services/WebAuthnService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/// <reference types="user-agent-data-types" /> <- add this line
import type { ClientCapabilities } from '@corbado/types';
import { create, get } from '@corbado/webauthn-json';
import { createResponseToJSON, getResponseToJSON } from '@corbado/webauthn-json/extended';
import FingerprintJS from '@fingerprintjs/fingerprintjs';
import { detectIncognito } from 'detectincognitojs';
import log from 'loglevel';
Expand Down Expand Up @@ -73,10 +74,17 @@ export class WebAuthnService {
} as never)) as PublicKeyCredential;
}

return {
response: JSON.stringify(credential.toJSON()),
message: '',
};
try {
return {
response: JSON.stringify(credential.toJSON()),
message: '',
};
} catch (e) {
return {
response: JSON.stringify(createResponseToJSON(credential)),
message: 'toJSON() not available on PublicKeyCredential',
};
}
}

async login(
Expand Down Expand Up @@ -125,10 +133,17 @@ export class WebAuthnService {
signal: abortController.signal,
})) as PublicKeyCredential;

return {
response: JSON.stringify(credential.toJSON()),
message: '',
};
try {
return {
response: JSON.stringify(credential.toJSON()),
message: '',
};
} catch (e) {
return {
response: JSON.stringify(getResponseToJSON(credential)),
message: 'toJSON() not available on PublicKeyCredential',
};
}
}

async getClientInformation(maybeClientHandle: ClientStateEntry<string> | undefined): Promise<ClientInformation> {
Expand Down
Loading