# 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.
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
/**
|
|
* Dependency injection seam for the shared Spring auth engine.
|
|
*
|
|
* The engine is created at import time (it starts a session-monitoring timer),
|
|
* so configuration is read lazily through {@link getSpringAuthConfig}. Hosts
|
|
* call {@link configureSpringAuth} once at startup:
|
|
*
|
|
* - Editor: injects its `@app/services/apiClient` plus a platform bridge built
|
|
* from its per-flavor `@app/extensions/*` seams, so desktop/saas behaviour is
|
|
* unchanged.
|
|
* - Portal: relies on the web defaults below (same-origin transport + no-op
|
|
* platform bridge).
|
|
*/
|
|
import type { AxiosInstance } from "axios";
|
|
import { createDefaultHttpClient } from "@shared/auth/httpClient";
|
|
import {
|
|
defaultPlatformBridge,
|
|
type PlatformBridge,
|
|
} from "@shared/auth/spring/platformBridge";
|
|
|
|
export interface SpringAuthConfig {
|
|
/** Axios instance used for all /api/v1/auth + /api/v1/user calls. */
|
|
http: AxiosInstance;
|
|
/** App base path (subpath deploys); used to build OAuth redirect targets. */
|
|
basePath: string;
|
|
/** Platform seam (web no-op by default; desktop injects Tauri behaviour). */
|
|
platform: PlatformBridge;
|
|
}
|
|
|
|
let config: SpringAuthConfig | null = null;
|
|
|
|
export function getSpringAuthConfig(): SpringAuthConfig {
|
|
if (!config) {
|
|
config = {
|
|
http: createDefaultHttpClient(),
|
|
basePath: "",
|
|
platform: defaultPlatformBridge,
|
|
};
|
|
}
|
|
return config;
|
|
}
|
|
|
|
/**
|
|
* Configure the shared Spring auth engine. Any field left undefined keeps its
|
|
* current (or default) value, so hosts can configure incrementally.
|
|
*/
|
|
export function configureSpringAuth(partial: Partial<SpringAuthConfig>): void {
|
|
const current = getSpringAuthConfig();
|
|
config = {
|
|
http: partial.http ?? current.http,
|
|
basePath: partial.basePath ?? current.basePath,
|
|
platform: partial.platform ?? current.platform,
|
|
};
|
|
}
|