feat: household api token auth foundation
This commit is contained in:
@@ -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),
|
||||
],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user