// Login-/Logout-Helfer für den Client (ADR 0001 §6). Konfiguration kommt aus configuration.auth (Server). const NATURALCRIT_LOGIN = 'https://www.naturalcrit.com/login'; const authConfig = ()=>(typeof global !== 'undefined' && global.config?.auth) || null; export const oidcEnabled = ()=>!!authConfig()?.providers?.includes('oidc'); export const naturalcritEnabled = ()=>{ const providers = authConfig()?.providers; return !providers || providers.includes('naturalcrit'); }; export const getOidcLabel = ()=>authConfig()?.oidcLabel || 'Anmelden'; // redirect: Pfad (mit Query) oder absolute URL; bei OIDC wird nur der Pfad verwendet export const getLoginUrl = (redirect = '/')=>{ const cfg = authConfig(); if(cfg?.loginUrl) { let path = redirect; try { const u = new URL(redirect, typeof window !== 'undefined' ? window.location.href : 'http://localhost'); path = `${u.pathname}${u.search}${u.hash}`; } catch { path = '/'; } return `${cfg.loginUrl}?redirect=${encodeURIComponent(path)}`; } if(!redirect || redirect === '/') return NATURALCRIT_LOGIN; const base = redirect.startsWith('/') ? (global.config?.baseUrl || global.config?.publicUrl || '') : ''; return `${NATURALCRIT_LOGIN}?redirect=${base}${redirect}`; }; export const getLogoutUrl = ()=>authConfig()?.logoutUrl || '/auth/logout'; // true, wenn der Client den Logout dem Server überlassen muss (httpOnly-Cookie) export const logoutViaServer = (account = typeof global !== 'undefined' ? global.account : undefined)=>account?.provider === 'oidc';