| 4 | |
| 5 | // Helper to check if user is admin based on Clerk metadata |
| 6 | async function checkIsAdmin(ctx: QueryCtx | MutationCtx): Promise<boolean> { |
| 7 | const identity = await ctx.auth.getUserIdentity() |
| 8 | if (!identity) return false |
| 9 | |
| 10 | // Check for admin role in Clerk public metadata (snake_case from JWT) |
| 11 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 12 | const metadata = (identity as any).public_metadata as { role?: string } | undefined |
| 13 | return metadata?.role === "admin" |
| 14 | } |
| 15 | |
| 16 | // Query to check if current user is admin (for UI) |
| 17 | export const isAdmin = query({ |