|
2 | 2 | /// <reference types="user-agent-data-types" /> <- add this line |
3 | 3 | import type { ClientCapabilities } from '@corbado/types'; |
4 | 4 | import { create, get } from '@corbado/webauthn-json'; |
| 5 | +import { createResponseToJSON, getResponseToJSON } from '@corbado/webauthn-json/extended'; |
5 | 6 | import FingerprintJS from '@fingerprintjs/fingerprintjs'; |
6 | 7 | import { detectIncognito } from 'detectincognitojs'; |
7 | 8 | import log from 'loglevel'; |
@@ -73,10 +74,17 @@ export class WebAuthnService { |
73 | 74 | } as never)) as PublicKeyCredential; |
74 | 75 | } |
75 | 76 |
|
76 | | - return { |
77 | | - response: JSON.stringify(credential.toJSON()), |
78 | | - message: '', |
79 | | - }; |
| 77 | + try { |
| 78 | + return { |
| 79 | + response: JSON.stringify(credential.toJSON()), |
| 80 | + message: '', |
| 81 | + }; |
| 82 | + } catch (e) { |
| 83 | + return { |
| 84 | + response: JSON.stringify(createResponseToJSON(credential)), |
| 85 | + message: 'toJSON() not available on PublicKeyCredential', |
| 86 | + }; |
| 87 | + } |
80 | 88 | } |
81 | 89 |
|
82 | 90 | async login( |
@@ -125,10 +133,17 @@ export class WebAuthnService { |
125 | 133 | signal: abortController.signal, |
126 | 134 | })) as PublicKeyCredential; |
127 | 135 |
|
128 | | - return { |
129 | | - response: JSON.stringify(credential.toJSON()), |
130 | | - message: '', |
131 | | - }; |
| 136 | + try { |
| 137 | + return { |
| 138 | + response: JSON.stringify(credential.toJSON()), |
| 139 | + message: '', |
| 140 | + }; |
| 141 | + } catch (e) { |
| 142 | + return { |
| 143 | + response: JSON.stringify(getResponseToJSON(credential)), |
| 144 | + message: 'toJSON() not available on PublicKeyCredential', |
| 145 | + }; |
| 146 | + } |
132 | 147 | } |
133 | 148 |
|
134 | 149 | async getClientInformation(maybeClientHandle: ClientStateEntry<string> | undefined): Promise<ClientInformation> { |
|
0 commit comments