first commit
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import { auth } from '@/lib/auth'
|
||||
import { NextResponse } from 'next/server'
|
||||
|
||||
export async function requireAdmin() {
|
||||
const session = await auth()
|
||||
if (!session || (session.user as { role?: string }).role !== 'ADMIN') {
|
||||
throw new Error('Unauthorized')
|
||||
}
|
||||
return session
|
||||
}
|
||||
|
||||
export function unauthorized() {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
Reference in New Issue
Block a user