MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / buildAppConfig

Function buildAppConfig

server/src/utils/html-config.ts:47–80  ·  view source on GitHub ↗
(user?: AppUser | null)

Source from the content-addressed store, hash-verified

45 * Works with req.user populated by optionalAuth middleware.
46 */
47export function buildAppConfig(user?: AppUser | null): {
48 authEnabled: boolean;
49 user: { id?: string; email: string; firstName?: string | null; lastName?: string | null; isAdmin: boolean; isMember: boolean } | null;
50 posthog: { apiKey: string; host: string } | null;
51} {
52 // Trust a pre-resolved isAdmin (set by enrichUserWithAdmin / dev-user flag).
53 // Fall back to ADMIN_EMAILS for callers that haven't enriched yet so we don't
54 // regress from prior behavior.
55 let isAdmin = false;
56 if (user) {
57 if (typeof user.isAdmin === 'boolean') {
58 isAdmin = user.isAdmin;
59 } else {
60 const adminEmails = process.env.ADMIN_EMAILS?.split(',').map(e => e.trim().toLowerCase()) || [];
61 isAdmin = adminEmails.includes(user.email.toLowerCase());
62 }
63 }
64
65 return {
66 authEnabled: AUTH_ENABLED,
67 user: user ? {
68 id: user.id,
69 email: user.email,
70 firstName: user.firstName,
71 lastName: user.lastName,
72 isAdmin,
73 isMember: !!user.isMember,
74 } : null,
75 posthog: POSTHOG_API_KEY ? {
76 apiKey: POSTHOG_API_KEY,
77 host: POSTHOG_HOST,
78 } : null,
79 };
80}
81
82/**
83 * Generate the script tag to inject app config into HTML.

Callers 1

getAppConfigScriptFunction · 0.70

Calls 1

trimMethod · 0.65

Tested by

no test coverage detected