feat: household api token auth foundation

This commit is contained in:
ginnoir
2026-07-04 18:57:31 -05:00
parent 2c0c31540e
commit ea5d1d050c
11 changed files with 465 additions and 32 deletions
+25
View File
@@ -1,4 +1,5 @@
import type { AdapterAccountType } from "@auth/core/adapters";
import { sql } from "drizzle-orm";
import {
boolean,
index,
@@ -209,3 +210,27 @@ export const notifications = pgTable(
},
(t) => [index("notifications_user_read_idx").on(t.userId, t.readAt)],
);
export const householdApiTokens = pgTable(
"household_api_tokens",
{
id: uuid("id").primaryKey().defaultRandom(),
householdId: uuid("household_id")
.notNull()
.references(() => households.id, { onDelete: "cascade" }),
tokenHash: text("token_hash").notNull(),
name: text("name").notNull().default("default"),
createdBy: uuid("created_by")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
lastUsedAt: timestamp("last_used_at", { withTimezone: true }),
revokedAt: timestamp("revoked_at", { withTimezone: true }),
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
},
(t) => [
uniqueIndex("household_api_tokens_active_household_uq")
.on(t.householdId)
.where(sql`${t.revokedAt} IS NULL`),
index("household_api_tokens_hash_idx").on(t.tokenHash),
],
);