Wire production domain, CORS for tenant subdomains, celery volume mounts, and nginx reverse proxy configs for apex, API, identity, auth, and wildcard tenants. Co-authored-by: Cursor <cursoragent@cursor.com>
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
/**
|
|
* SSO اختیاری برای زیرسیستمها (مثلاً منوی دیجیتال کافه).
|
|
* اگر کاربر قبلاً در هسته مرکزی login کرده، دوباره login لازم نیست.
|
|
*/
|
|
|
|
import { getStoredToken, loginWithRedirect } from "@/lib/auth";
|
|
|
|
/** آیا کاربر در SSO مرکزی احراز شده؟ */
|
|
export function hasCentralSsoSession(): boolean {
|
|
return !!getStoredToken();
|
|
}
|
|
|
|
/**
|
|
* اگر SSO لازم باشد و session نباشد، به Keycloak هدایت میکند.
|
|
* @returns true اگر session موجود است (میتوان ادامه داد)
|
|
*/
|
|
export async function ensureCentralSsoOrRedirect(returnPath: string): Promise<boolean> {
|
|
if (hasCentralSsoSession()) return true;
|
|
await loginWithRedirect(returnPath);
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* برای API زیرسیستم — هدر Authorization با توکن مرکزی (در صورت وجود).
|
|
*/
|
|
export function optionalSsoAuthHeader(): Record<string, string> {
|
|
const token = getStoredToken();
|
|
return token ? { Authorization: `Bearer ${token}` } : {};
|
|
}
|