Authenticate a User with a Passkey Credential
1. Initialize the Passkey Client
import { Turnkey, TurnkeySDKBrowserConfig } from "@turnkey/sdk-browser";
import turnkeyConfig from "./turnkey.json"
const turnkey = new Turnkey(turnkeyConfig);
const passkeyClient = turnkey.passkeyClient();
2. Call the login
function
const response = await passkeyClient.login();
if (response.organizationId) {
navigate("/authenticated-route")
} else {
navigate("/not-authenticated-route")
}
3. Make read requests on behalf of the authenticated user from the currentUserSession
const currentUserSession = await turnkey.currentUserSession();
const walletsResponse = await currentUserSession.getWallets()
const walletName = walletsResponse.wallets[0].walletName
4. Call the passkeyClient
directly for write requests
This will always prompt a user to confirm the action with their passkey credential
import { DEFAULT_ETHEREUM_ACCOUNTS } from "@turnkey/sdk-browser";
const newWalletResponse = await passkeyClient.createWallet({
walletName: "New Wallet for User",
accounts: DEFAULT_ETHEREUM_ACCOUNTS
})