This commit is contained in:
eric
2026-03-12 03:54:22 -05:00
parent 421f979e10
commit e7dde61e31
23 changed files with 876 additions and 125 deletions

View File

@@ -2,7 +2,18 @@ import { NextRequest, NextResponse } from "next/server";
import { getPocketBaseConfig } from "@/config/services.config";
import { getThemeConfig } from "@/config";
function getOrCreateUserId(): string {
const COOKIE_NAME = "pb_session";
function getOrCreateUserId(request: NextRequest): string {
const cookie = request.cookies.get(COOKIE_NAME)?.value;
if (cookie) {
try {
const payload = JSON.parse(Buffer.from(cookie, "base64url").toString("utf-8"));
if (payload?.userId) return payload.userId;
} catch {
/* ignore */
}
}
return `user${Date.now()}`;
}
@@ -24,7 +35,7 @@ async function getAdminToken(): Promise<string | null> {
export async function POST(request: NextRequest) {
try {
const userId = getOrCreateUserId();
const userId = getOrCreateUserId(request);
const body = await request.json();
const formData = body && typeof body === "object" ? body : {};