This commit is contained in:
eric
2026-03-12 03:54:50 -05:00
parent 170a9939aa
commit 40230dd646
20 changed files with 645 additions and 95 deletions

View File

@@ -1,7 +1,18 @@
import { NextRequest, NextResponse } from "next/server";
import { getPocketBaseConfig } from "@/config/services.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()}`;
}
@@ -23,7 +34,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 : {};