Files
vesta/lib/auth-helpers.ts
T
2026-07-30 12:15:17 +03:00

15 lines
388 B
TypeScript

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 })
}