* Generate the script tags to inject app config and PostHog into HTML.
(user?: { id?: string; email: string; firstName?: string | null; lastName?: string | null; isMember?: boolean; isAdmin?: boolean } | null)
| 445 | * Generate the script tags to inject app config and PostHog into HTML. |
| 446 | */ |
| 447 | function getAppConfigScript(user?: { id?: string; email: string; firstName?: string | null; lastName?: string | null; isMember?: boolean; isAdmin?: boolean } | null): string { |
| 448 | const config = buildAppConfig(user); |
| 449 | const configScript = `<script>window.__APP_CONFIG__=${JSON.stringify(config)};</script>`; |
| 450 | |
| 451 | // Add PostHog script if API key is configured |
| 452 | const posthogScript = POSTHOG_API_KEY |
| 453 | ? `<script src="/posthog-init.js" defer></script>` |
| 454 | : ''; |
| 455 | |
| 456 | // csrf.js patches fetch() to include the X-CSRF-Token header on POSTs |
| 457 | const csrfScript = `<script src="/csrf.js"></script>`; |
| 458 | |
| 459 | return `${configScript}\n${csrfScript}\n${posthogScript}`; |
| 460 | } |
| 461 | |
| 462 | /** |
| 463 | * Get user info from request for HTML config injection. |
no test coverage detected