Skip to main content
function usePasskeyAuth(): {
  passkeyAccount: any;
  sessionKey: any;
  isAuthenticated: boolean;
  hasPasskeySupport: boolean;
  sessionSecrets: SessionSecrets;
  isLoading: any;
  loadingOperation: any;
  error: any;
  errorCode: any;
  sessionStatus: PasskeySessionStatus;
  sessionExpiresAt: number;
  ensureValidSession: () => Promise<void>;
  checkSupport: () => Promise<boolean>;
  hasLocalPasskeyAccount: () => boolean;
  createAccount: (params) => Promise<void>;
  authenticate: (params) => Promise<void>;
  logout: () => void;
  clearError: () => void;
};
Passkey authentication hook for Grid SDK Provides a unified passkey-based authentication flow using WebAuthn for biometric authentication. Supports both account creation (signup) and authentication (login) with existing passkeys. Key Features:
  • Browser passkey support detection
  • Account creation with biometric enrollment
  • Authentication with existing passkeys
  • Session management with expiration tracking
  • Duplicate account prevention

Returns

Object containing authentication state and methods
NameTypeDefault valueDescription
passkeyAccountanystoredState.passkeyAccount-
sessionKeyanystoredState.sessionKey-
isAuthenticatedbooleanstoredState.isAuthenticated-
hasPasskeySupportbooleanstoredState.hasPasskeySupport-
sessionSecretsSessionSecrets--
isLoadingany--
loadingOperationany--
errorany--
errorCodeany--
sessionStatusPasskeySessionStatus--
sessionExpiresAtnumber--
ensureValidSession()() => Promise<void>-Ensure the passkey session is valid and ready for use
checkSupport()() => Promise<boolean>-Check if browser supports passkey authentication
hasLocalPasskeyAccount()() => boolean-Check if user has already created a passkey account on this device Uses localStorage to track created accounts
createAccount()(params) => Promise<void>-Create a new passkey account (signup flow) This method performs the complete passkey account creation: 1. Generates session key for signing 2. Creates passkey session with the API 3. Prompts user for biometric authentication (WebAuthn) 4. Creates both passkey account and smart account 5. Stores account and session data
authenticate()(params) => Promise<void>-Authenticate with an existing passkey (login flow) This method performs passkey authentication: 1. Generates session key for signing 2. Creates authorize session with the API 3. Prompts user for biometric authentication 4. Finds existing passkey account 5. Stores account and session data
logout()() => void-Log out and clear all stored passkey authentication data Clears all browser storage (localStorage and sessionStorage) and disconnects the account from the SDK context. Note: You can also use useAccount().disconnect() directly for the same behavior.
clearError()() => void-Clear error state

Example

import { usePasskeyAuth } from '@sqds/grid-react';

function PasskeyAuth() {
  const { authenticate, createAccount, isAuthenticated, passkeyAccount } = usePasskeyAuth();

  if (isAuthenticated) return <div>Address: {passkeyAccount.data.address}</div>;

  return <button onClick={authenticate}>Sign In</button>;
}