debug(auth): log session cookie source
This commit is contained in:
@@ -7,12 +7,19 @@
|
||||
* Environment Variables:
|
||||
* - NEXT_PUBLIC_API_URL: The main API server URL (default: http://localhost:3001)
|
||||
* - NEXT_PUBLIC_ORCHESTRATOR_URL: The orchestrator service URL (default: same as API URL)
|
||||
* - NEXT_PUBLIC_AUTH_MODE: Auth mode for web app (`real` or `mock`)
|
||||
* - If unset: development defaults to `mock`, production defaults to `real`
|
||||
*/
|
||||
|
||||
/**
|
||||
* Default API server URL for local development
|
||||
*/
|
||||
const DEFAULT_API_URL = "http://localhost:3001";
|
||||
const DEFAULT_AUTH_MODE = process.env.NODE_ENV === "development" ? "mock" : "real";
|
||||
|
||||
const VALID_AUTH_MODES = ["real", "mock"] as const;
|
||||
|
||||
export type AuthMode = (typeof VALID_AUTH_MODES)[number];
|
||||
|
||||
/**
|
||||
* Main API server URL
|
||||
@@ -20,6 +27,34 @@ const DEFAULT_API_URL = "http://localhost:3001";
|
||||
*/
|
||||
export const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL ?? DEFAULT_API_URL;
|
||||
|
||||
function resolveAuthMode(): AuthMode {
|
||||
const rawMode = (process.env.NEXT_PUBLIC_AUTH_MODE ?? DEFAULT_AUTH_MODE).toLowerCase();
|
||||
|
||||
if (!VALID_AUTH_MODES.includes(rawMode as AuthMode)) {
|
||||
throw new Error(
|
||||
`Invalid NEXT_PUBLIC_AUTH_MODE "${rawMode}". Expected one of: ${VALID_AUTH_MODES.join(", ")}.`
|
||||
);
|
||||
}
|
||||
|
||||
if (rawMode === "mock" && process.env.NODE_ENV !== "development") {
|
||||
throw new Error("NEXT_PUBLIC_AUTH_MODE=mock is only allowed when NODE_ENV=development.");
|
||||
}
|
||||
|
||||
return rawMode as AuthMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authentication mode for frontend runtime.
|
||||
* - real: uses normal BetterAuth/Backend session flow
|
||||
* - mock: local-only seeded mock user for FE development
|
||||
*/
|
||||
export const AUTH_MODE: AuthMode = resolveAuthMode();
|
||||
|
||||
/**
|
||||
* Whether local mock auth mode is enabled.
|
||||
*/
|
||||
export const IS_MOCK_AUTH_MODE = AUTH_MODE === "mock";
|
||||
|
||||
/**
|
||||
* Orchestrator service URL
|
||||
* Used for agent management, task progress, and orchestration features
|
||||
@@ -53,6 +88,8 @@ export const apiConfig = {
|
||||
baseUrl: API_BASE_URL,
|
||||
/** Orchestrator service URL */
|
||||
orchestratorUrl: ORCHESTRATOR_URL,
|
||||
/** Authentication mode (`real` or `mock`) */
|
||||
authMode: AUTH_MODE,
|
||||
/** Build full API URL for an endpoint */
|
||||
buildUrl: buildApiUrl,
|
||||
/** Build full orchestrator URL for an endpoint */
|
||||
|
||||
Reference in New Issue
Block a user