Initialize the Passkey Client
import { Turnkey } from "@turnkey/sdk-browser"; const turnkey = new Turnkey({ apiBaseUrl: "https://api.turnkey.com", defaultOrganizationId: process.env.TURNKEY_ORGANIZATION_ID, }); const passkeyClient = turnkey.passkeyClient();
Call the login function
const response = await passkeyClient.login(); if (response.organizationId) { navigate("/authenticated-route"); } else { navigate("/not-authenticated-route"); }
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;
Call the passkeyClient directly for write requests
import { DEFAULT_ETHEREUM_ACCOUNTS } from "@turnkey/sdk-browser"; const newWalletResponse = await passkeyClient.createWallet({ walletName: "New Wallet for User", accounts: DEFAULT_ETHEREUM_ACCOUNTS, });
Was this page helpful?