's'
This commit is contained in:
@@ -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 : {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user