Skip to content

Commit 6ce2491

Browse files
committed
Update SERDE in WebAuthnService
1 parent e73ce03 commit 6ce2491

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

packages/web-core/src/services/WebAuthnService.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/// <reference types="user-agent-data-types" /> <- add this line
33
import type { ClientCapabilities } from '@corbado/types';
44
import { create, get } from '@corbado/webauthn-json';
5+
import { createResponseToJSON, getResponseToJSON } from '@corbado/webauthn-json/extended';
56
import FingerprintJS from '@fingerprintjs/fingerprintjs';
67
import { detectIncognito } from 'detectincognitojs';
78
import log from 'loglevel';
@@ -73,10 +74,17 @@ export class WebAuthnService {
7374
} as never)) as PublicKeyCredential;
7475
}
7576

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+
}
8088
}
8189

8290
async login(
@@ -125,10 +133,17 @@ export class WebAuthnService {
125133
signal: abortController.signal,
126134
})) as PublicKeyCredential;
127135

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+
}
132147
}
133148

134149
async getClientInformation(maybeClientHandle: ClientStateEntry<string> | undefined): Promise<ClientInformation> {

0 commit comments

Comments
 (0)