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

@@ -37,6 +37,7 @@ export const create = async (
id: user.id,
email: user.email,
stripeCustomerId: user.stripeCustomerId,
emailVerified: false,
})
.returning();

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();

View File

@@ -1,4 +1,6 @@
export * from "./auth";
export * from "./boards";
export * from "./auth";
export * from "./cards";
export * from "./feedback";
export * from "./imports";

View File

@@ -1,5 +1,11 @@
import { relations } from "drizzle-orm";
import { pgTable, timestamp, uuid, varchar } from "drizzle-orm/pg-core";
import { relations, sql } from "drizzle-orm";
import {
boolean,
pgTable,
timestamp,
uuid,
varchar,
} from "drizzle-orm/pg-core";
import { boards } from "./boards";
import { cards } from "./cards";
@@ -8,11 +14,16 @@ import { lists } from "./lists";
import { workspaceMembers, workspaces } from "./workspaces";
export const users = pgTable("user", {
id: uuid("id").notNull().primaryKey(),
id: uuid("id")
.notNull()
.primaryKey()
.default(sql`uuid_generate_v4()`),
name: varchar("name", { length: 255 }),
email: varchar("email", { length: 255 }).notNull().unique(),
emailVerified: timestamp("emailVerified", { mode: "date" }),
emailVerified: boolean("emailVerified").notNull(),
image: varchar("image", { length: 255 }),
createdAt: timestamp("createdAt").notNull().defaultNow(),
updatedAt: timestamp("updatedAt").notNull().defaultNow(),
stripeCustomerId: varchar("stripeCustomerId", { length: 255 }),
}).enableRLS();