@@ -61,11 +61,11 @@ constructor:
6161
6262<TabItem value = " table" >
6363
64- | Parameter | Description |
65- | ----------- | --------------------------------------------------------------------------------------------- |
66- | ` rpID? ` | Your app domain. If your app is hosted on "your.app.xyz", the RPID can be "your.app.xyz". |
67- | ` rpName? ` | Name of your app. We recommend setting it to the correctly capitalized name of your app. |
68- | ` buildEnv? ` | Specifies the build environment to use: ` production ` , ` staging ` , ` testing ` , or ` development ` . |
64+ | Parameter | Description |
65+ | ----------- | ----------------------------------------------------------------------------------------------------------------------- |
66+ | ` rpID? ` | Stands for relying party ID. Your app domain. If your app is hosted on "your.app.xyz", the RPID can be "your.app.xyz". |
67+ | ` rpName? ` | Stands for relying party name. Name of your app. We recommend setting it to the correctly capitalized name of your app. |
68+ | ` buildEnv? ` | Specifies the build environment to use: ` production ` , ` staging ` , ` testing ` , or ` development ` . |
6969
7070</TabItem >
7171
@@ -137,8 +137,8 @@ console.log(passkeys);
137137
138138:::note Note
139139
140- First, a user needs to log in the usual way, and then register a passkey. From the next time, they
141- can log in using a passkey.
140+ First, a user needs to log in the usual way, and then register a passkey. The next time, they can
141+ log in using a passkey.
142142
143143:::
144144
@@ -199,7 +199,9 @@ console.log(passkeys);
199199
200200Below are two files, ` App.tsx ` and ` utils.ts ` , demonstrating the implementation of the Passkeys SFA
201201Plugin. The ` utils.ts ` file is kept non-opinionated and can be configured according to your
202- requirements for your users.
202+ requirements for your users. Also, note that the passkeys flow is ** only supported on browsers that
203+ support WebAuthn** . You need to check for browser support before registering or logging in with a
204+ passkey.
203205
204206:::
205207
@@ -213,10 +215,11 @@ requirements for your users.
213215
214216<TabItem value = " App.tsx" >
215217
216- ``` javascript
218+ ``` typescript
217219import { CHAIN_NAMESPACES , WEB3AUTH_NETWORK , IProvider } from " @web3auth/base" ;
218220import Web3Auth from " @web3auth/single-factor-auth" ;
219221import { PasskeysPlugin } from " @web3auth/passkeys-sfa-plugin" ;
222+ import { shouldSupportPasskey } from " ./utils" ;
220223
221224const clientId = " Your_Web3Auth_Client_ID" ;
222225
@@ -245,25 +248,44 @@ const passkeysPlugin = new PasskeysPlugin({
245248
246249web3auth .addPlugin (passkeysPlugin ); // Add the plugin to web3auth
247250
248- // Register a new passkey
249- await passkeysPlugin .registerPasskey ({ username: " user@example.com" });
251+ await web3auth .init ();
250252
251- // Login with an existing passkey
252- await passkeysPlugin .loginWithPasskey ({ authenticatorId: " authenticator_id" });
253+ await web3auth .connect ({
254+ verifier: " your_verifier_name" , // Pass the verifier name created on the Web3Auth dashboard
255+ verifierId: " your_verifier_id" , // Pass the verifierId received from the OAuth provider
256+ idToken: " id_token" , // Pass the idToken received from the OAuth provider
257+ });
253258
254- // List all registered passkeys
255- const passkeys = await passkeysPlugin .listAllPasskeys ();
256- console .log (passkeys);
259+ const result = shouldSupportPasskey ();
260+
261+ if (! result .isBrowserSupported ) {
262+ console .log (" Browser not supported" );
263+ } else {
264+ // Register a new passkey
265+ await passkeysPlugin .registerPasskey ({ username: " user@example.com" });
266+
267+ // Login with an existing passkey
268+ await passkeysPlugin .loginWithPasskey ({ authenticatorId: " authenticator_id" });
269+
270+ // List all registered passkeys
271+ const passkeys = await passkeysPlugin .listAllPasskeys ();
272+ console .log (passkeys );
273+ }
257274```
258275
259276</TabItem >
260277
261278<TabItem value = " utils.ts" >
262279
263- ``` javascript
280+ ``` typescript
264281import bowser from " bowser" ;
265282
266- const PASSKEYS_ALLOWED_MAP = [bowser .OS_MAP .iOS , bowser .OS_MAP .MacOS , bowser .OS_MAP .Android , bowser .OS_MAP .Windows ];
283+ const PASSKEYS_ALLOWED_MAP = [
284+ bowser .OS_MAP .iOS ,
285+ bowser .OS_MAP .MacOS ,
286+ bowser .OS_MAP .Android ,
287+ bowser .OS_MAP .Windows ,
288+ ];
267289
268290const getWindowsVersion = (osVersion : string ) => {
269291 const windowsVersionRegex = / NT (\d + \. \d + )/ ;
@@ -293,9 +315,13 @@ const checkIfOSIsSupported = (osName: string, osVersion: string) => {
293315 }
294316};
295317
296- export function shouldSupportPasskey (): { isBrowserSupported: boolean; isOsSupported: boolean; supported
318+ export function shouldSupportPasskey(): {
319+ isBrowserSupported: boolean ;
320+ isOsSupported: boolean ;
321+ supported;
297322
298- Browser?: Record< string, string> } {
323+ Browser? : Record <string , string >;
324+ } {
299325 const browser = bowser .getParser (navigator .userAgent );
300326 const osDetails = browser .parseOS ();
301327 if (! osDetails ) return { isBrowserSupported: false , isOsSupported: false };
@@ -325,8 +351,9 @@ Browser?: Record<string, string> } {
325351}
326352
327353export function browserSupportsWebAuthn() {
328- return (window ? .PublicKeyCredential !== undefined &&
329- typeof window .PublicKeyCredential === ' function' );
354+ return (
355+ window ?.PublicKeyCredential !== undefined && typeof window .PublicKeyCredential === " function"
356+ );
330357}
331358```
332359
0 commit comments