NODEDC_TASKMANAGER/plane-src/apps/web/helpers/nodedc-auth.ts

55 lines
1.5 KiB
TypeScript

export function shouldUseNodeDCOIDC(): boolean {
const flag = process.env.VITE_NODEDC_OIDC_LOGIN_ENABLED;
if (flag === "1" || flag === "true") {
return true;
}
if (flag === "0" || flag === "false") {
return false;
}
if (typeof window === "undefined") {
return false;
}
const hostname = window.location.hostname.toLowerCase();
return hostname.endsWith(".local.nodedc") || hostname.endsWith(".notdc.ru") || hostname.endsWith(".nodedc.ru");
}
export function buildNodeDCOIDCLoginUrl(nextPath?: string | null): string {
const configuredUrl = process.env.VITE_NODEDC_OIDC_LOGIN_URL || "/auth/oidc/login/";
const url = new URL(configuredUrl, window.location.origin);
const safeNextPath = sanitizeNextPath(nextPath || getCurrentRelativePath());
if (safeNextPath) {
url.searchParams.set("next_path", safeNextPath);
}
return url.toString();
}
export function buildNodeDCLauncherUrl(): string {
return process.env.VITE_NODEDC_LAUNCHER_URL || "http://launcher.local.nodedc/";
}
export function buildNodeDCBrandConfigUrl(): string {
return new URL("/api/public/brand", buildNodeDCLauncherUrl()).toString();
}
export function getCurrentRelativePath(): string {
if (typeof window === "undefined") {
return "/";
}
return `${window.location.pathname}${window.location.search}`;
}
export function sanitizeNextPath(value?: string | null): string {
if (!value || !value.startsWith("/") || value.startsWith("//")) {
return "/";
}
return value;
}