Authenticate a User with a Passkey Credential
1. 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();
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,
});