( userId: string, )
| 58 | * Returns the admin user if authorized, null if not |
| 59 | */ |
| 60 | export 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 | } |
no test coverage detected