JavaScript SDK

React hooks

AuthContextProvider, useAuth and useScuteClient from @scute/react-hooks.

@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>;}
scuteClientScuteClientrequired
The client. In Next.js, use createClientComponentClient().
childrenReactNoderequired
Your app.
acceptImpersonationHandoffboolean
Take a "sign in as this user" hand-off when the page opens with ?sct_imp=<code>: the code is removed from the address bar and swapped for the session. Default true.

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>;}
FieldType
sessionSession: status is "loading", "authenticated" or "unauthenticated"
userScuteUserData, or null while loading or signed out
isAuthenticatedtrue when the session is authenticated and the user is loaded
isLoadingtrue 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#

HookPage
useEnrollMfa, useMfaVerify, useFactorList, useBackupCodesMFA hooks
useCan, usePermissions, useImpersonationAuthorization hooks
useScuteAuthFlow, useUserProfile, useSessions, useAlternatePhones, useSecureAccountIn @scute/auth-ui-react: Headless sign-in, Account hooks