15 lines
778 B
TypeScript
15 lines
778 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { requireUser } from "@/lib/auth";
|
|
import { db } from "@/lib/db";
|
|
import { externalUrl } from "@/lib/http";
|
|
import { requireSameOrigin } from "@/lib/security";
|
|
|
|
export async function POST(req: Request) {
|
|
try {
|
|
requireSameOrigin(req); const user = await requireUser(); const form = await req.formData(); const id = Number(form.get("id"));
|
|
if (id) db.prepare("UPDATE notifications SET read_at=CURRENT_TIMESTAMP WHERE id=? AND user_id=?").run(id, user.id);
|
|
else db.prepare("UPDATE notifications SET read_at=CURRENT_TIMESTAMP WHERE user_id=? AND read_at IS NULL").run(user.id);
|
|
return NextResponse.redirect(externalUrl(req, "/notifications"));
|
|
} catch { return NextResponse.redirect(externalUrl(req, "/")); }
|
|
}
|