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.
76 lines
2.3 KiB
TypeScript
76 lines
2.3 KiB
TypeScript
/**
|
|
* Shared, provider-agnostic auth used by both the editor and the portal.
|
|
*
|
|
* Hosts configure a backend once at startup:
|
|
* - Spring: configureSpringAuth({ http, basePath, platform }) then render
|
|
* <AuthProvider mode="spring">.
|
|
* - Supabase: configureSupabase({ url, key }) then render
|
|
* <AuthProvider mode="supabase">.
|
|
*
|
|
* Consumers read state via useAuth(); guards (RequireAuth/RequireAdmin) gate UI.
|
|
*/
|
|
|
|
// Contract + helpers
|
|
export * from "@shared/auth/types";
|
|
export { isAdminRole } from "@shared/auth/roles";
|
|
export { AuthContext, useAuth } from "@shared/auth/context";
|
|
|
|
// Unified provider + guards
|
|
export {
|
|
AuthProvider,
|
|
type AuthProviderProps,
|
|
} from "@shared/auth/AuthProvider";
|
|
export {
|
|
RequireAuth,
|
|
type RequireAuthProps,
|
|
} from "@shared/auth/guards/RequireAuth";
|
|
export {
|
|
RequireAdmin,
|
|
type RequireAdminProps,
|
|
} from "@shared/auth/guards/RequireAdmin";
|
|
|
|
// Spring backend
|
|
export {
|
|
configureSpringAuth,
|
|
getSpringAuthConfig,
|
|
type SpringAuthConfig,
|
|
} from "@shared/auth/config";
|
|
export {
|
|
type PlatformBridge,
|
|
type PlatformSessionUser,
|
|
defaultPlatformBridge,
|
|
} from "@shared/auth/spring/platformBridge";
|
|
export {
|
|
createDefaultHttpClient,
|
|
getStoredToken,
|
|
setStoredToken,
|
|
clearStoredToken,
|
|
JWT_STORAGE_KEY,
|
|
} from "@shared/auth/httpClient";
|
|
export {
|
|
SpringAuthProvider,
|
|
deriveDisplayName,
|
|
} from "@shared/auth/spring/UseSession";
|
|
export {
|
|
springAuth,
|
|
setPostLoginRedirectPath,
|
|
consumePostLoginRedirectPath,
|
|
isSafePostLoginRedirect,
|
|
POST_LOGIN_REDIRECT_STORAGE_KEY,
|
|
getCurrentUser,
|
|
isUserAnonymous,
|
|
createAnonymousUser,
|
|
createAnonymousSession,
|
|
} from "@shared/auth/spring/springAuthClient";
|
|
export type { OAuthProvider } from "@shared/auth/spring/oauthTypes";
|
|
|
|
// Supabase backend is intentionally NOT re-exported here: doing so would pull
|
|
// @supabase/supabase-js into every barrel consumer (e.g. the portal in Spring
|
|
// mode). Supabase-mode hosts import directly from the subpath:
|
|
// import { configureSupabase } from "@shared/auth/supabase/supabaseClient";
|
|
// The unified <AuthProvider mode="supabase"> lazy-loads the provider on demand.
|
|
|
|
// Login UI components live under @shared/auth/ui/* and are imported directly
|
|
// (default exports), e.g. `import OAuthButtons from "@shared/auth/ui/OAuthButtons"`.
|
|
// They use react-i18next, so hosts must initialise i18next.
|