implement better-auth auth with postgres and route protection

This commit is contained in:
2026-02-24 13:32:43 -05:00
parent fd168f607c
commit 52a4ab38d3
31 changed files with 1202 additions and 89 deletions

View File

@@ -1,4 +1,5 @@
import { jsonError } from '@/lib/server/http';
import { requireAuthenticatedSession } from '@/lib/server/auth-session';
import { withStore } from '@/lib/server/store';
type Context = {
@@ -6,6 +7,12 @@ type Context = {
};
export async function DELETE(_request: Request, context: Context) {
const { session, response } = await requireAuthenticatedSession();
if (response) {
return response;
}
const userId = session.user.id;
const { id } = await context.params;
const numericId = Number(id);
@@ -16,7 +23,7 @@ export async function DELETE(_request: Request, context: Context) {
let removed = false;
await withStore((store) => {
const next = store.watchlist.filter((item) => item.id !== numericId);
const next = store.watchlist.filter((item) => !(item.id === numericId && item.user_id === userId));
removed = next.length !== store.watchlist.length;
store.watchlist = next;
});