- Next.js 16 + Tailwind + shadcn/ui skeleton - Auth.js v5 generic OIDC (Pocket ID, PKCE) with optional group gate - proxy.ts gates all pages and API routes - Drizzle schema (models, files, jobs, logs, worker state) on SQLite/libsql - Worker skeleton: migrations, interrupted-job recovery, heartbeat Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16 lines
635 B
TypeScript
16 lines
635 B
TypeScript
import "server-only";
|
|
import type { Session } from "next-auth";
|
|
import { NextResponse } from "next/server";
|
|
import { auth } from "@/auth";
|
|
|
|
type Handler<Ctx> = (req: Request, ctx: Ctx & { session: Session }) => Promise<Response> | Response;
|
|
|
|
/** Wraps a route handler so it only runs for a logged-in user (defense in depth behind proxy.ts). */
|
|
export function withAuth<Ctx = unknown>(handler: Handler<Ctx>) {
|
|
return async (req: Request, ctx: Ctx) => {
|
|
const session = await auth();
|
|
if (!session?.user) return NextResponse.json({ error: "unauthorized" }, { status: 401 });
|
|
return handler(req, { ...ctx, session });
|
|
};
|
|
}
|