ФУНКЦИИ - МЕЖПРОЕКТНАЯ КОММУНИКАЦИЯ: Plane live access и logout handoff
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
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 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;
|
||||
}
|
||||
Reference in New Issue
Block a user