- lib/session.ts: isAdmin: boolean toegevoegd
- lib/auth-guard.ts: requireAdmin() toegevoegd
- actions/admin/jobs.ts: cancelJobAction (CUID-validatie, eindstatus-check → CANCELLED),
deleteJobAction (hard delete) — beide 'use server', revalidatePath('/admin/jobs')
32 lines
795 B
TypeScript
32 lines
795 B
TypeScript
import { redirect } from 'next/navigation'
|
|
import { getSession } from '@/lib/auth'
|
|
import { isPairedSessionExpired } from '@/lib/auth/pairing'
|
|
|
|
/**
|
|
* Layout-side auth guard. Returns the session when valid; otherwise redirects
|
|
* to /login (and destroys an expired paired-session first).
|
|
*
|
|
* Used by both `app/(app)/layout.tsx` (desktop) and `app/(mobile)/layout.tsx`.
|
|
*/
|
|
export async function requireSession() {
|
|
const session = await getSession()
|
|
|
|
if (!session.userId) {
|
|
redirect('/login')
|
|
}
|
|
|
|
if (isPairedSessionExpired(session)) {
|
|
await session.destroy()
|
|
redirect('/login')
|
|
}
|
|
|
|
return session
|
|
}
|
|
|
|
export async function requireAdmin() {
|
|
const session = await getSession()
|
|
if (!session.userId || !session.isAdmin) {
|
|
redirect('/dashboard')
|
|
}
|
|
return session
|
|
}
|