@microwiseai/ist-identity-react
v0.2.0
Published
React bindings for IST identity (Firebase IdP -> ist-identity SSOT). Drop-in replacement for @ist/auth.
Downloads
14
Readme
@ist/identity-react
React bindings for the ist-identity SSOT. Drop-in replacement for @ist/auth.
Firebase is used only as an external IdP; the canonical identity is the Firebase uid adopted by ist-identity. There are no Firestore writes — all identity is persisted via the identity-api Worker.
Surface (compatible with @ist/auth)
AuthProvider,useAuth(),LoginButton(Mantine)getFirebaseApp(),getFirebaseAuth()— parity shimsfirebaseConfig—integrated-sessionproject config
import { AuthProvider, useAuth, LoginButton } from '@ist/identity-react';
<AuthProvider>
<App />
</AuthProvider>;
// Base URL defaults to the canonical identity-api; override per-build with the
// VITE_IST_API_URL env, or at runtime via the `baseUrl` prop.useAuth() → AuthContextType
{
user: IstUser | null; // { uid, username, displayName?, email?, photoURL? }
isLoggedIn: boolean;
isLoading: boolean;
token: string | null; // IST JWT (HS256)
signInWithGoogle: () => Promise<void>;
signOut: () => Promise<void>;
getToken: () => Promise<string>; // compat shim for old user.getIdToken()
}uid / username / token are IST canonical identity; displayName / email
/ photoURL are runtime-only profile fields from the IdP (never stored
server-side).
Flow (model C)
- signInWithGoogle: Firebase Google popup →
getIdToken()→POST /api/auth/provider { provider:'firebase', idToken }→{ uid, token, username }. Session cached inlocalStorage; runtime Firebase profile merged in-memory. - mount: restore
{ uid, token, username }fromlocalStorageand gate on it synchronously via a localexpdecode (isLoggedIn=.tokenpresent + locally-not-expired). No network verify gates the UI — authoritative verification happens server-side at point-of-use (perauth-credential-schema). The asyncverifyIstTokenhelper stays exported for opt-in checks, not as a gate. - getToken: returns the cached IST JWT, re-exchanging via the IdP near expiry.
- signOut: clears the local session and signs out of the IdP.
- authBypass (dev-only):
?authBypass=trueinjects a fake session for headless tests. Gated behindimport.meta.env.DEV— disabled in production bundles.
Firebase is optional
The core provider is IdP-agnostic. The Firebase adapter is loaded lazily (dynamic
import('./firebase.js')) only when a Firebase sign-in actually happens; inject a
custom IdpAdapter via the idp prop for other IdPs or tests.
Dependencies
dependencies:@ist/identitypeerDependencies:react,react-dom,firebase(optional),@mantine/core(optional),@tabler/icons-react(optional)
