Admin panel for VinEye with dashboard, users, diseases, guides, alerts management. Stack: Next.js App Router + Prisma + PostgreSQL + better-auth. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
29 lines
696 B
TypeScript
29 lines
696 B
TypeScript
import { auth } from "./auth";
|
|
import { headers } from "next/headers";
|
|
|
|
export async function getSession() {
|
|
const session = await auth.api.getSession({
|
|
headers: await headers(),
|
|
});
|
|
return session;
|
|
}
|
|
|
|
export async function requireAuth() {
|
|
const session = await getSession();
|
|
if (!session) {
|
|
return { error: "Unauthorized", status: 401 } as const;
|
|
}
|
|
return { session } as const;
|
|
}
|
|
|
|
export async function requireAdmin() {
|
|
const session = await getSession();
|
|
if (!session) {
|
|
return { error: "Unauthorized", status: 401 } as const;
|
|
}
|
|
if (session.user.role !== "ADMIN") {
|
|
return { error: "Forbidden", status: 403 } as const;
|
|
}
|
|
return { session } as const;
|
|
}
|