MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / checkAdminAuth

Function checkAdminAuth

web/src/app/api/admin/admin-auth.ts:12–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10 * Returns the admin user if authorized, or a NextResponse error if not
11 */
12export async function checkAdminAuth(): Promise<
13 utils.AdminUser | NextResponse
14> {
15 const session = await getServerSession(authOptions)
16
17 // Use shared admin check utility
18 const adminUser = await utils.checkSessionIsAdmin(session)
19 if (!adminUser) {
20 if (session?.user?.id) {
21 logger.warn(
22 { userId: session.user.id },
23 'Unauthorized access attempt to admin endpoint',
24 )
25 }
26 return NextResponse.json(
27 { error: 'Forbidden - not an admin' },
28 { status: 403 },
29 )
30 }
31
32 return adminUser
33}
34
35/**
36 * Higher-order function to wrap admin API routes with authentication

Callers 11

PATCHFunction · 0.90
GETFunction · 0.90
POSTFunction · 0.90
GETFunction · 0.90
GETFunction · 0.90
POSTFunction · 0.90
GETFunction · 0.90
GETFunction · 0.90
GETFunction · 0.90
GETFunction · 0.90
withAdminAuthFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected