MCPcopy
hub / github.com/CodebuffAI/codebuff / checkUserIsCodebuffAdmin

Function checkUserIsCodebuffAdmin

packages/internal/src/utils/auth.ts:60–93  ·  view source on GitHub ↗
(
  userId: string,
)

Source from the content-addressed store, hash-verified

58 * Returns the admin user if authorized, null if not
59 */
60export async function checkUserIsCodebuffAdmin(
61 userId: string,
62): Promise<AdminUser | null> {
63 try {
64 // Get the user from the database to verify email
65 const user = await db
66 .select({
67 id: schema.user.id,
68 email: schema.user.email,
69 name: schema.user.name,
70 })
71 .from(schema.user)
72 .where(eq(schema.user.id, userId))
73 .then((users: any) => users[0])
74
75 if (!user?.email) {
76 return null
77 }
78
79 const isAdmin = isCodebuffAdmin(user.email)
80 if (!isAdmin) {
81 return null
82 }
83
84 return {
85 id: user.id,
86 email: user.email,
87 name: user.name,
88 }
89 } catch (error) {
90 console.error('checkUserIsCodebuffAdmin: Database error', error)
91 return null
92 }
93}

Callers 1

checkSessionIsAdminFunction · 0.85

Calls 2

isCodebuffAdminFunction · 0.85
fromMethod · 0.80

Tested by

no test coverage detected