backend: per-user settings store (/api/settings) + enable account deletion

- user_settings table (userId PK -> user, jsonb preferences) + migration
- GET/PUT /api/settings (requireAuth, user-scoped; zod-validated flat map)
- Better Auth user.deleteUser enabled so users can delete their own account

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Khalid Abdi
2026-06-10 20:05:34 +03:00
parent da245b8758
commit 50fbb6cd40
9 changed files with 2636 additions and 0 deletions
+1
View File
@@ -7,3 +7,4 @@ export * from "./tasks.js";
export * from "./activity.js";
export * from "./messaging.js";
export * from "./notifications.js";
export * from "./settings.js";
+20
View File
@@ -0,0 +1,20 @@
import { jsonb, pgTable, text, timestamp } from "drizzle-orm/pg-core";
import { user } from "./auth.js";
// Per-user preferences (notification toggles, profile extras). One row per
// user, keyed by the Better Auth user id; the payload is a flat JSONB map so
// the frontend can add settings without a migration.
export const userSettings = pgTable("user_settings", {
userId: text("user_id")
.primaryKey()
.references(() => user.id, { onDelete: "cascade" }),
preferences: jsonb("preferences")
.$type<Record<string, boolean | string>>()
.notNull()
.default({}),
updatedAt: timestamp("updated_at")
.defaultNow()
.$onUpdate(() => new Date())
.notNull(),
});