Some checks failed
Build and Push Docker Image / build (push) Has been cancelled
- Add roles UserRole[] to User model with migration + backfill from existing role column - Update auth JWT/session to propagate roles array with [role] fallback for stale tokens - Update tRPC hasRole() middleware and add userHasRole() helper for inline role checks - Update ~15 router inline checks and ~13 DB queries to use roles array - Add updateRoles admin mutation with SUPER_ADMIN guard and priority-based primary role - Add role switcher UI in admin sidebar and role-nav for multi-role users - Remove redundant stats cards from round detail, add window dates to header banner - Merge Members section into JuryProgressTable with inline cap editor and remove buttons - Reorder round detail assignments tab: Progress > Score Dist > Assignments > Coverage > Jury Group - Make score distribution fill full vertical height, reassignment history always open - Add per-juror progress bars to admin dashboard ActiveRoundPanel for EVALUATION rounds - Fix evaluation submit bug: use isSubmitting state instead of startMutation.isPending Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
32 lines
878 B
TypeScript
32 lines
878 B
TypeScript
import { redirect } from 'next/navigation'
|
|
import type { Route } from 'next'
|
|
import { auth } from '@/lib/auth'
|
|
import type { UserRole } from '@prisma/client'
|
|
|
|
const ROLE_DASHBOARDS: Record<string, string> = {
|
|
SUPER_ADMIN: '/admin',
|
|
PROGRAM_ADMIN: '/admin',
|
|
JURY_MEMBER: '/jury',
|
|
MENTOR: '/mentor',
|
|
OBSERVER: '/observer',
|
|
APPLICANT: '/applicant',
|
|
}
|
|
|
|
export async function requireRole(...allowedRoles: UserRole[]) {
|
|
const session = await auth()
|
|
|
|
if (!session?.user) {
|
|
redirect('/login')
|
|
}
|
|
|
|
// Use roles array, fallback to [role] for stale JWT tokens
|
|
const userRoles = session.user.roles?.length ? session.user.roles : [session.user.role]
|
|
|
|
if (!allowedRoles.some(r => userRoles.includes(r))) {
|
|
const dashboard = ROLE_DASHBOARDS[session.user.role]
|
|
redirect((dashboard || '/login') as Route)
|
|
}
|
|
|
|
return session
|
|
}
|