Apply full refactor updates plus pipeline/email UX confirmations
All checks were successful
Build and Push Docker Image / build (push) Successful in 10m33s
All checks were successful
Build and Push Docker Image / build (push) Successful in 10m33s
This commit is contained in:
@@ -1,30 +1,30 @@
|
||||
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')
|
||||
}
|
||||
|
||||
const userRole = session.user.role
|
||||
|
||||
if (!allowedRoles.includes(userRole)) {
|
||||
const dashboard = ROLE_DASHBOARDS[userRole]
|
||||
redirect((dashboard || '/login') as Route)
|
||||
}
|
||||
|
||||
return session
|
||||
}
|
||||
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')
|
||||
}
|
||||
|
||||
const userRole = session.user.role
|
||||
|
||||
if (!allowedRoles.includes(userRole)) {
|
||||
const dashboard = ROLE_DASHBOARDS[userRole]
|
||||
redirect((dashboard || '/login') as Route)
|
||||
}
|
||||
|
||||
return session
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user