Initial commit: MOPC platform with Docker deployment setup
Full Next.js 15 platform with tRPC, Prisma, PostgreSQL, NextAuth. Includes production Dockerfile (multi-stage, port 7600), docker-compose with registry-based image pull, Gitea Actions CI workflow, nginx config for portal.monaco-opc.com, deployment scripts, and DEPLOYMENT.md guide. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
29
src/lib/auth-redirect.ts
Normal file
29
src/lib/auth-redirect.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
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',
|
||||
}
|
||||
|
||||
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