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

Function enrichUserWithAdmin

server/src/utils/html-config.ts:150–171  ·  view source on GitHub ↗
(user: AppUser | null | undefined)

Source from the content-addressed store, hash-verified

148 * group. If the user already has isAdmin set (e.g. a dev user), trust it.
149 */
150export async function enrichUserWithAdmin(user: AppUser | null | undefined): Promise<AppUser | null | undefined> {
151 if (!user) return user;
152 if (typeof user.isAdmin === 'boolean') return user;
153
154 const adminEmails = process.env.ADMIN_EMAILS?.split(',').map(e => e.trim().toLowerCase()) || [];
155 if (adminEmails.includes(user.email.toLowerCase())) {
156 user.isAdmin = true;
157 return user;
158 }
159
160 if (user.id) {
161 try {
162 user.isAdmin = await isWebUserAAOAdmin(user.id);
163 } catch (error) {
164 logger.warn({ error, userId: user.id }, 'Failed to resolve isAdmin via working group; defaulting to false');
165 user.isAdmin = false;
166 }
167 } else {
168 user.isAdmin = false;
169 }
170 return user;
171}
172
173/**
174 * Enrich a user object with membership status from the database.

Callers 6

setupMiddlewareMethod · 0.85
serveHtmlWithConfigMethod · 0.85
setupRoutesMethod · 0.85
serveDashboardPageMethod · 0.85
serveHtmlWithConfigFunction · 0.85
serveHtmlWithMetaTagsFunction · 0.85

Calls 3

isWebUserAAOAdminFunction · 0.85
warnMethod · 0.80
trimMethod · 0.65

Tested by

no test coverage detected