UNPKG

@azuro-org/sdk

Version:

One-stop solution for building betting dApps on the Azuro Protocol.

48 lines (47 loc) 1.58 kB
import { type ChainId } from '@azuro-org/toolkit'; import { type Address } from 'viem'; export type AuthErrorCode = 'NoWallet' | 'NotAuthenticated' | 'UserRejectedSignature' | 'NonceRequestFailed' | 'VerifyFailed' | 'NetworkError' | 'StorageUnavailable'; export declare class AuthError extends Error { code: AuthErrorCode; constructor(code: AuthErrorCode, message: string, options?: { cause?: unknown; }); } export type UseAuthProps = { affiliate: Address; chainId?: ChainId; statement?: string; domain?: string; uri?: string; autoSignIn?: boolean; onSignIn?: (token: string) => void; onSignOut?: () => void; onError?: (err: AuthError) => void; }; export type UseAuthResult = { token: string | null; isAuthenticated: boolean; isLoading: boolean; error: AuthError | null; signIn: () => Promise<string>; signOut: () => void; }; /** * Authenticate a user via Sign-In With Ethereum (SIWE), persisting the resulting JWT token * in localStorage and keeping it in sync across browser tabs. * * Supports both regular wallets and Account Abstraction (AA) wallets. * * - Docs: https://gem.azuro.org/hub/apps/sdk/auth/useAuth * * @example * import { useAuth } from '@azuro-org/sdk' * * const { token, isAuthenticated, isLoading, signIn, signOut, error } = useAuth({ * affiliate: '0x...', * autoSignIn: true, * onSignIn: (token) => console.log('Signed in!', token), * onSignOut: () => console.log('Signed out'), * }) * */ export declare const useAuth: (props: UseAuthProps) => UseAuthResult;