feat: setup better-auth

This commit is contained in:
Henry
2025-05-02 23:40:34 +01:00
parent 5996ad19c3
commit 091fea6f38
23 changed files with 4696 additions and 30 deletions

View File

@@ -0,0 +1,77 @@
import {
bigserial,
boolean,
integer,
pgTable,
text,
timestamp,
uuid,
} from "drizzle-orm/pg-core";
import { users } from "./users";
export const session = pgTable("session", {
id: bigserial("id", { mode: "number" }).primaryKey(),
expiresAt: timestamp("expiresAt").notNull(),
token: text("token").notNull().unique(),
createdAt: timestamp("createdAt").notNull(),
updatedAt: timestamp("updatedAt").notNull(),
ipAddress: text("ipAddress"),
userAgent: text("userAgent"),
userId: uuid("userId")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
}).enableRLS();
export const account = pgTable("account", {
id: bigserial("id", { mode: "number" }).primaryKey(),
accountId: text("accountId").notNull(),
providerId: text("providerId").notNull(),
userId: uuid("userId")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
accessToken: text("accessToken"),
refreshToken: text("refreshToken"),
idToken: text("idToken"),
accessTokenExpiresAt: timestamp("accessTokenExpiresAt"),
refreshTokenExpiresAt: timestamp("refreshTokenExpiresAt"),
scope: text("scope"),
password: text("password"),
createdAt: timestamp("createdAt").notNull(),
updatedAt: timestamp("updatedAt").notNull(),
}).enableRLS();
export const verification = pgTable("verification", {
id: bigserial("id", { mode: "number" }).primaryKey(),
identifier: text("identifier").notNull(),
value: text("value").notNull(),
expiresAt: timestamp("expiresAt").notNull(),
createdAt: timestamp("createdAt"),
updatedAt: timestamp("updatedAt"),
}).enableRLS();
export const apiKey = pgTable("apiKey", {
id: bigserial("id", { mode: "number" }).primaryKey(),
name: text("name"),
start: text("start"),
prefix: text("prefix"),
key: text("key").notNull(),
userId: uuid("userId")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
refillInterval: integer("refillInterval"),
refillAmount: integer("refillAmount"),
lastRefillAt: timestamp("lastRefillAt"),
enabled: boolean("enabled"),
rateLimitEnabled: boolean("rateLimitEnabled"),
rateLimitTimeWindow: integer("rateLimitTimeWindow"),
rateLimitMax: integer("rateLimitMax"),
requestCount: integer("requestCount"),
remaining: integer("remaining"),
lastRequest: timestamp("lastRequest"),
expiresAt: timestamp("expiresAt"),
createdAt: timestamp("createdAt").notNull(),
updatedAt: timestamp("updatedAt").notNull(),
permissions: text("permissions"),
metadata: text("metadata"),
}).enableRLS();