The user must have already signed in via another method (e.g. email/password, social, etc.) and added a passkey to their account before they can use it to sign in with.You can prompt a user to add a passkey to their account using your SDK’s passkey registration method (see SDK-specific Tabs) or by directing them to the “Account & Security” section of the Dynamic Widget.
Dashboard Configuration
Simply toggle on “Passkey” in the Log in & User Profile section of the dashboard.
Using our UI
Once toggled on, these methods will be available in the Dynamic widget.
Using your UI
React
React Native
Javascript
Swift
Flutter
All we will need for this use case is the useSignInWithPasskey hook.Once you have those available in your component, the rest is as simple as building your form!Code Example
import { useSignInWithPasskey } from '@dynamic-labs/sdk-react-core';
const App = () => {
const signInWithPasskey = useSignInWithPasskey();
return (
<button
onClick={() => signInWithPasskey()}
>
Sign in with passkey
</button>
);
};
import { dynamicClient } from '<path to client file>';
// Primary sign-in with passkey (1FA)
await dynamicClient.auth.passkey.signIn({
relatedOriginRpId: 'example.com', // Optional, if you want to sign in from a related origin
});
// Register a new passkey for the signed-in user
await dynamicClient.passkeys.register();
// MFA authenticate using an existing passkey
await dynamicClient.passkeys.authenticateMFA({
relatedOriginRpId: 'example.com', // Optional, if you want to authenticate from a related origin
});
Prerequisites
- You need to have the Dynamic Client initialized (See this guide on how to do that).
Usage
import { signInWithPasskey } from '@dynamic-labs-sdk/client';
// Call signInWithPasskey to prompt the user to authenticate with a passkey.
// Once the user authenticates with the passkey, they will be signed in.
const handlePasskeySignIn = async () => {
await signInWithPasskey();
};
Coming soon
Coming soon