Files
Stirling-PDF/frontend/shared/auth/AuthProvider.tsx
T
James Brunton 1816bad1ba Unified auth for portal and editor (#6725)
# Description of Changes
Refactor frontend auth to the shared folder and hook it up to both the
portal and editor so they share the same system. Also adds various tasks
to help run the portal, including `task dev:portal` to spawn the portal
with the backend, and `task dev:portal:proxy` to spawn the editor,
portal and backend, and a reverse proxy (at localhost:3000) to allow you
to use both at once to simulate how this will actually be deployed,
allowing you to check whether the seamless transition between the two
actually works.
2026-06-22 16:22:36 +00:00

44 lines
1.3 KiB
TypeScript

/**
* Unified auth provider. Selects the Spring (self-hosted JWT) or Supabase
* (cloud) backend by `mode` and feeds the single shared AuthContext, so
* consumers read `useAuth()` identically either way.
*/
import { lazy, Suspense, type ReactNode } from "react";
import { SpringAuthProvider } from "@shared/auth/spring/UseSession";
import { type AuthMode, type AuthTranslate } from "@shared/auth/types";
// Lazy so Spring-mode hosts (e.g. the portal) don't bundle @supabase/supabase-js
// they never use; only loaded when mode="supabase".
const SupabaseAuthProvider = lazy(() =>
import("@shared/auth/supabase/UseSession").then((m) => ({
default: m.SupabaseAuthProvider,
})),
);
export interface AuthProviderProps {
children: ReactNode;
/** Which backend to authenticate against. Defaults to "spring". */
mode?: AuthMode;
/** Optional i18n translate for user-facing copy (defaults to English). */
translate?: AuthTranslate;
}
export function AuthProvider({
children,
mode = "spring",
translate,
}: AuthProviderProps) {
if (mode === "supabase") {
return (
<Suspense fallback={null}>
<SupabaseAuthProvider translate={translate}>
{children}
</SupabaseAuthProvider>
</Suspense>
);
}
return (
<SpringAuthProvider translate={translate}>{children}</SpringAuthProvider>
);
}