mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2026-09-03 05:10:16 +03:00
# 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.
44 lines
1.3 KiB
TypeScript
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>
|
|
);
|
|
}
|