@scute/react-hooks puts a ScuteClient in React context and keeps the session in React state. It re-exports everything in @scute/js-core, so createClient and the error classes import from here too. It works with React 16.8 to 19 and marks its modules "use client".
AuthContextProvider#
import { useState } from "react";import { AuthContextProvider, createClient } from "@scute/react-hooks";export function Providers({ children }: { children: React.ReactNode }) { const [scuteClient] = useState(() => createClient({ appId: import.meta.env.VITE_SCUTE_APP_ID })); return <AuthContextProvider scuteClient={scuteClient}>{children}</AuthContextProvider>;}The provider subscribes to onAuthStateChange and updates its state on session events only (initial_session, signed_in, signed_out, session_expired, session_refetch, token_refreshed, webauthn_register_start, webauthn_register_success).
useAuth#
import { useAuth } from "@scute/react-hooks";function Account() { const { isLoading, isAuthenticated, user, session, signOut } = useAuth(); if (isLoading) return null; if (!isAuthenticated) return <a href="/sign-in">Sign in</a>; return <button onClick={() => signOut()}>Sign out {user.email}</button>;}| Field | Type |
|---|---|
| session | Session: status is "loading", "authenticated" or "unauthenticated" |
| user | ScuteUserData, or null while loading or signed out |
| isAuthenticated | true when the session is authenticated and the user is loaded |
| isLoading | true until the first session is resolved |
| signOut | () => Promise<boolean>; see Sessions |
With isAuthenticated: true, TypeScript narrows user to ScuteUserData. useAuth throws outside AuthContextProvider.
useScuteClient#
import { useScuteClient } from "@scute/react-hooks";function MagicLinkButton({ email }: { email: string }) { const scute = useScuteClient(); return <button onClick={() => scute.signInOrUp(email)}>Email me a link</button>;}Returns the provider's ScuteClient for any call in Core client. Throws outside the provider.
Other hooks#
| Hook | Page |
|---|---|
| useEnrollMfa, useMfaVerify, useFactorList, useBackupCodes | MFA hooks |
| useCan, usePermissions, useImpersonation | Authorization hooks |
| useScuteAuthFlow, useUserProfile, useSessions, useAlternatePhones, useSecureAccount | In @scute/auth-ui-react: Headless sign-in, Account hooks |