40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
|
|
'use client'
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Halal Monitor Bridge
|
||
|
|
* Passes auth credentials from FalahMobile to the World Monitor iframe
|
||
|
|
* via localStorage and postMessage.
|
||
|
|
*/
|
||
|
|
|
||
|
|
const WORLD_MONITOR_URL = process.env.NEXT_PUBLIC_WORLD_MONITOR_URL || 'https://halal.worldmonitor.app'
|
||
|
|
|
||
|
|
export function getWorldMonitorUrl(): string {
|
||
|
|
return WORLD_MONITOR_URL
|
||
|
|
}
|
||
|
|
|
||
|
|
export function getWorldMonitorIframeUrl(path?: string): string {
|
||
|
|
const base = WORLD_MONITOR_URL
|
||
|
|
const variant = 'halal'
|
||
|
|
return path ? `${base}/${path}?variant=${variant}` : `${base}/?variant=${variant}`
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface HalalAuthPayload {
|
||
|
|
type: 'flh-auth'
|
||
|
|
token: string
|
||
|
|
user: {
|
||
|
|
id: string
|
||
|
|
name: string
|
||
|
|
email: string
|
||
|
|
isPremium: boolean
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export function broadcastAuthToIframe(iframe: HTMLIFrameElement | null, auth: {
|
||
|
|
token: string
|
||
|
|
user: { id: string; name: string; email: string; isPremium: boolean }
|
||
|
|
}) {
|
||
|
|
if (!iframe?.contentWindow) return
|
||
|
|
const payload: HalalAuthPayload = { type: 'flh-auth', ...auth }
|
||
|
|
iframe.contentWindow.postMessage(payload, WORLD_MONITOR_URL)
|
||
|
|
}
|