KI-AGENT: Persistente App-Sessions mit Refresh-Tokens ergänzen

This commit is contained in:
2026-07-20 22:01:08 +02:00
parent d8273e794d
commit 657a4f9e85
11 changed files with 405 additions and 60 deletions

View File

@@ -0,0 +1,21 @@
CREATE TABLE IF NOT EXISTS "auth_refresh_tokens" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"user_id" uuid NOT NULL,
"tenant_id" bigint,
"token_hash" text NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"expires_at" timestamp with time zone NOT NULL,
"revoked_at" timestamp with time zone,
CONSTRAINT "auth_refresh_tokens_token_hash_unique" UNIQUE("token_hash"),
CONSTRAINT "auth_refresh_tokens_user_id_auth_users_id_fk"
FOREIGN KEY ("user_id") REFERENCES "public"."auth_users"("id")
ON DELETE cascade ON UPDATE cascade,
CONSTRAINT "auth_refresh_tokens_tenant_id_tenants_id_fk"
FOREIGN KEY ("tenant_id") REFERENCES "public"."tenants"("id")
ON DELETE set null ON UPDATE cascade
);
CREATE INDEX IF NOT EXISTS "auth_refresh_tokens_user_id_idx"
ON "auth_refresh_tokens" ("user_id");
CREATE INDEX IF NOT EXISTS "auth_refresh_tokens_expires_at_idx"
ON "auth_refresh_tokens" ("expires_at");

View File

@@ -372,6 +372,13 @@
"when": 1784021669805,
"tag": "0055_tenant_export_maintenance_lock",
"breakpoints": true
},
{
"idx": 53,
"version": "7",
"when": 1784548800000,
"tag": "0056_auth_refresh_tokens",
"breakpoints": true
}
]
}

View File

@@ -0,0 +1,20 @@
import { pgTable, text, timestamp, uuid, bigint } from "drizzle-orm/pg-core"
import { authUsers } from "./auth_users"
import { tenants } from "./tenants"
export const authRefreshTokens = pgTable("auth_refresh_tokens", {
id: uuid("id").primaryKey().defaultRandom(),
userId: uuid("user_id")
.notNull()
.references(() => authUsers.id, { onDelete: "cascade", onUpdate: "cascade" }),
tenantId: bigint("tenant_id", { mode: "number" })
.references(() => tenants.id, { onDelete: "set null", onUpdate: "cascade" }),
tokenHash: text("token_hash").notNull().unique(),
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
revokedAt: timestamp("revoked_at", { withTimezone: true }),
})
export type AuthRefreshToken = typeof authRefreshTokens.$inferSelect
export type NewAuthRefreshToken = typeof authRefreshTokens.$inferInsert

View File

@@ -7,6 +7,7 @@ export * from "./auth_roles"
export * from "./auth_tenant_users"
export * from "./auth_user_roles"
export * from "./auth_users"
export * from "./auth_refresh_tokens"
export * from "./bankaccounts"
export * from "./bankrequisitions"
export * from "./bankstatements"