From 68c330a51a9812b51e4a11a45eca64ba579be254 Mon Sep 17 00:00:00 2001 From: TZGyn Date: Sun, 20 Aug 2023 02:38:26 +0800 Subject: [PATCH] Update add bookmark to include credentials --- app/api/bookmark/route.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/api/bookmark/route.ts b/app/api/bookmark/route.ts index 74f1df7..43da5b0 100644 --- a/app/api/bookmark/route.ts +++ b/app/api/bookmark/route.ts @@ -3,6 +3,8 @@ import { NextRequest, NextResponse } from 'next/server' import { bookmark } from '@/lib/schema' import { db } from '@/lib/db' import { eq } from 'drizzle-orm' +import { cookies } from 'next/headers' +import { getUser } from '@/lib/auth' export const GET = async () => { const bookmarks = await db.select().from(bookmark) @@ -12,11 +14,17 @@ export const GET = async () => { export const POST = async (request: NextRequest) => { const body = await request.json() + const token = cookies().get('token') + + const session_user = await getUser(token) const newBookmark = newBookmarkSchema.safeParse(body) if (newBookmark.success) { - await db.insert(bookmark).values(newBookmark.data) + await db.insert(bookmark).values({ + ...newBookmark.data, + userId: session_user ? session_user.id : null, + }) return NextResponse.json({ status: 200 }) }