This setup fits any client-rendered React app (Vite and others). Remix, TanStack Start and Astro use the same provider; see Other frameworks.
Install#
npm install @scute/react-hooks@next @scute/auth-ui-react@nextVITE_SCUTE_APP_ID=YOUR_APP_IDThe SDK does not read this variable itself: your code passes it to createClient.
Create the provider
src/scute-providers.tsxtsximport { useState, type ReactNode } from "react";import { AuthContextProvider, createClient } from "@scute/react-hooks";import { ScuteAuthGate } from "@scute/auth-ui-react";export function ScuteProviders({ children }: { children: ReactNode }) { const [scute] = useState(() => createClient({ appId: import.meta.env.VITE_SCUTE_APP_ID })); return ( <AuthContextProvider scuteClient={scute}> <ScuteAuthGate>{children}</ScuteAuthGate> </AuthContextProvider> );}Create one client per app ID. A second client for the same app ID in one browser logs a warning, since the two can disagree about the session.
Wrap the app
src/main.tsxtsximport { createRoot } from "react-dom/client";import { ScuteProviders } from "./scute-providers";import { App } from "./App";createRoot(document.getElementById("root")!).render( <ScuteProviders> <App /> </ScuteProviders>);Use the session
src/App.tsxtsximport { useAuth } from "@scute/react-hooks";export function App() { const { user, signOut } = useAuth(); return ( <main> <p>Signed in as {user?.email ?? user?.phone}</p> <button onClick={() => signOut()}>Sign out</button> </main> );}
Session storage#
A browser client keeps the access and refresh tokens in localStorage, under keys suffixed with the app ID, and syncs sign-in and sign-out across tabs. To keep the refresh token out of JavaScript, use Next.js, which moves it into an httpOnly cookie, or pass your own storage adapter (see Client setup).
Your server#
Send the access token to your API and check it there. scute.getAuthToken() returns the current access token, refreshed first when it is about to expire.
const { data } = await scute.getAuthToken();await fetch("/api/orders", { headers: { Authorization: `Bearer ${data?.access}` } });On the server, see Authenticate requests.