mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 02:45:39 -04:00
First user to register automatically becomes admin and registration closes. Admins can re-open registration from a new settings page. Uses Better Auth admin plugin for role management and a new appSettings table for the registration flag. Mobile tab bar now links to settings instead of inline logout. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { headers } from "next/headers";
|
|
import { NextResponse } from "next/server";
|
|
import { auth } from "@/lib/auth/server";
|
|
import { getSetting, setSetting } from "@/lib/services/settings";
|
|
|
|
export async function GET() {
|
|
const session = await auth.api.getSession({ headers: await headers() });
|
|
if (!session)
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
if (session.user.role !== "admin")
|
|
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
|
|
|
const registrationOpen = (await getSetting("registrationOpen")) === "true";
|
|
return NextResponse.json({ registrationOpen });
|
|
}
|
|
|
|
export async function POST(request: Request) {
|
|
const session = await auth.api.getSession({ headers: await headers() });
|
|
if (!session)
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
if (session.user.role !== "admin")
|
|
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
|
|
|
const body = await request.json();
|
|
if (typeof body.registrationOpen === "boolean") {
|
|
await setSetting("registrationOpen", String(body.registrationOpen));
|
|
}
|
|
|
|
return NextResponse.json({ success: true });
|
|
}
|