organized
This commit is contained in:
parent
d2b5cf6516
commit
9dc2d9f320
6 changed files with 76 additions and 106 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
DB_USERNAME=
|
DB_USER=
|
||||||
DB_PASSWORD=
|
DB_PASSWORD=
|
||||||
DB_PORT=
|
DB_PORT=
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
import { pgTable, text, timestamp, boolean } from "drizzle-orm/pg-core";
|
|
||||||
|
|
||||||
export const user = pgTable("user", {
|
|
||||||
id: text("id").primaryKey(),
|
|
||||||
name: text("name").notNull(),
|
|
||||||
email: text("email").notNull().unique(),
|
|
||||||
emailVerified: boolean("email_verified").notNull(),
|
|
||||||
image: text("image"),
|
|
||||||
createdAt: timestamp("created_at").notNull(),
|
|
||||||
updatedAt: timestamp("updated_at").notNull(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const session = pgTable("session", {
|
|
||||||
id: text("id").primaryKey(),
|
|
||||||
expiresAt: timestamp("expires_at").notNull(),
|
|
||||||
token: text("token").notNull().unique(),
|
|
||||||
createdAt: timestamp("created_at").notNull(),
|
|
||||||
updatedAt: timestamp("updated_at").notNull(),
|
|
||||||
ipAddress: text("ip_address"),
|
|
||||||
userAgent: text("user_agent"),
|
|
||||||
userId: text("user_id")
|
|
||||||
.notNull()
|
|
||||||
.references(() => user.id),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const account = pgTable("account", {
|
|
||||||
id: text("id").primaryKey(),
|
|
||||||
accountId: text("account_id").notNull(),
|
|
||||||
providerId: text("provider_id").notNull(),
|
|
||||||
userId: text("user_id")
|
|
||||||
.notNull()
|
|
||||||
.references(() => user.id),
|
|
||||||
accessToken: text("access_token"),
|
|
||||||
refreshToken: text("refresh_token"),
|
|
||||||
idToken: text("id_token"),
|
|
||||||
accessTokenExpiresAt: timestamp("access_token_expires_at"),
|
|
||||||
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
|
|
||||||
scope: text("scope"),
|
|
||||||
password: text("password"),
|
|
||||||
createdAt: timestamp("created_at").notNull(),
|
|
||||||
updatedAt: timestamp("updated_at").notNull(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const verification = pgTable("verification", {
|
|
||||||
id: text("id").primaryKey(),
|
|
||||||
identifier: text("identifier").notNull(),
|
|
||||||
value: text("value").notNull(),
|
|
||||||
expiresAt: timestamp("expires_at").notNull(),
|
|
||||||
createdAt: timestamp("created_at"),
|
|
||||||
updatedAt: timestamp("updated_at"),
|
|
||||||
});
|
|
||||||
|
|
@ -9,14 +9,14 @@ services:
|
||||||
|
|
||||||
db:
|
db:
|
||||||
image: postgres:latest
|
image: postgres:latest
|
||||||
env_file:
|
|
||||||
- .env
|
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: ${DB_USER}
|
POSTGRES_USER: ${DB_USER}
|
||||||
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
||||||
POSTGRES_DB: ${DB_NAME}
|
POSTGRES_DB: ${DB_NAME}
|
||||||
ports:
|
ports:
|
||||||
- "5432:5432"
|
- "${DB_PORT}:5432"
|
||||||
|
env_file:
|
||||||
|
- .env.services
|
||||||
volumes:
|
volumes:
|
||||||
- postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
|
||||||
|
|
@ -25,11 +25,11 @@ services:
|
||||||
ports:
|
ports:
|
||||||
- "9000:9000"
|
- "9000:9000"
|
||||||
- "9001:9001"
|
- "9001:9001"
|
||||||
|
env_file:
|
||||||
|
- .env.services
|
||||||
environment:
|
environment:
|
||||||
MINIO_ROOT_USER: ${MINIO_ROOT_USER}
|
MINIO_ROOT_USER: ${MINIO_ROOT_USER}
|
||||||
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
|
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
|
||||||
MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY}
|
|
||||||
MINIO_SECRET_KEY: ${MINIO_SECRET_KEY}
|
|
||||||
command: server /data --console-address ":9001"
|
command: server /data --console-address ":9001"
|
||||||
volumes:
|
volumes:
|
||||||
- minio_data:/data
|
- minio_data:/data
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
"dev": "bun run --watch src/index.ts",
|
"dev": "bun run --watch src/index.ts",
|
||||||
"email": "email dev --dir src/emails",
|
"email": "email dev --dir src/emails",
|
||||||
"db:studio": "drizzle-kit studio",
|
"db:studio": "drizzle-kit studio",
|
||||||
|
"auth:generate": "bun x @better-auth/cli generate --config src/lib/auth/auth.ts --output src/db/schema.ts && drizzle-kit migrate",
|
||||||
"db:check": "drizzle-kit check",
|
"db:check": "drizzle-kit check",
|
||||||
"db:generate": "drizzle-kit generate",
|
"db:generate": "drizzle-kit generate",
|
||||||
"db:migrate": "drizzle-kit migrate",
|
"db:migrate": "drizzle-kit migrate",
|
||||||
|
|
|
||||||
|
|
@ -1,53 +1,54 @@
|
||||||
import { pgTable, pgSchema, text, timestamp, boolean } from "drizzle-orm/pg-core";
|
import { pgTable, text, integer, timestamp, boolean } from "drizzle-orm/pg-core";
|
||||||
|
|
||||||
|
export const user = pgTable("user", {
|
||||||
|
id: text("id").primaryKey(),
|
||||||
|
name: text('name').notNull(),
|
||||||
|
email: text('email').notNull().unique(),
|
||||||
|
emailVerified: boolean('email_verified').notNull(),
|
||||||
|
image: text('image'),
|
||||||
|
createdAt: timestamp('created_at').notNull(),
|
||||||
|
updatedAt: timestamp('updated_at').notNull()
|
||||||
|
});
|
||||||
|
|
||||||
export const auth_schema = pgSchema("auth")
|
export const session = pgTable("session", {
|
||||||
|
id: text("id").primaryKey(),
|
||||||
|
expiresAt: timestamp('expires_at').notNull(),
|
||||||
|
token: text('token').notNull().unique(),
|
||||||
|
createdAt: timestamp('created_at').notNull(),
|
||||||
|
updatedAt: timestamp('updated_at').notNull(),
|
||||||
|
ipAddress: text('ip_address'),
|
||||||
|
userAgent: text('user_agent'),
|
||||||
|
userId: text('user_id').notNull().references(()=> user.id)
|
||||||
|
});
|
||||||
|
|
||||||
export const user = auth_schema.table("user", {
|
export const account = pgTable("account", {
|
||||||
id: text("id").primaryKey(),
|
id: text("id").primaryKey(),
|
||||||
name: text("name").notNull(),
|
accountId: text('account_id').notNull(),
|
||||||
email: text("email").notNull().unique(),
|
providerId: text('provider_id').notNull(),
|
||||||
emailVerified: boolean("email_verified").notNull(),
|
userId: text('user_id').notNull().references(()=> user.id),
|
||||||
image: text("image"),
|
accessToken: text('access_token'),
|
||||||
createdAt: timestamp("created_at").notNull(),
|
refreshToken: text('refresh_token'),
|
||||||
updatedAt: timestamp("updated_at").notNull(),
|
idToken: text('id_token'),
|
||||||
});
|
accessTokenExpiresAt: timestamp('access_token_expires_at'),
|
||||||
|
refreshTokenExpiresAt: timestamp('refresh_token_expires_at'),
|
||||||
|
scope: text('scope'),
|
||||||
|
password: text('password'),
|
||||||
|
createdAt: timestamp('created_at').notNull(),
|
||||||
|
updatedAt: timestamp('updated_at').notNull()
|
||||||
|
});
|
||||||
|
|
||||||
export const session = auth_schema.table("session", {
|
export const verification = pgTable("verification", {
|
||||||
id: text("id").primaryKey(),
|
id: text("id").primaryKey(),
|
||||||
expiresAt: timestamp("expires_at").notNull(),
|
identifier: text('identifier').notNull(),
|
||||||
token: text("token").notNull().unique(),
|
value: text('value').notNull(),
|
||||||
createdAt: timestamp("created_at").notNull(),
|
expiresAt: timestamp('expires_at').notNull(),
|
||||||
updatedAt: timestamp("updated_at").notNull(),
|
createdAt: timestamp('created_at'),
|
||||||
ipAddress: text("ip_address"),
|
updatedAt: timestamp('updated_at')
|
||||||
userAgent: text("user_agent"),
|
});
|
||||||
userId: text("user_id")
|
|
||||||
.notNull()
|
|
||||||
.references(() => user.id),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const account = auth_schema.table("account", {
|
export const rateLimit = pgTable("rate_limit", {
|
||||||
id: text("id").primaryKey(),
|
id: text("id").primaryKey(),
|
||||||
accountId: text("account_id").notNull(),
|
key: text('key'),
|
||||||
providerId: text("provider_id").notNull(),
|
count: integer('count'),
|
||||||
userId: text("user_id")
|
lastRequest: integer('last_request')
|
||||||
.notNull()
|
});
|
||||||
.references(() => user.id),
|
|
||||||
accessToken: text("access_token"),
|
|
||||||
refreshToken: text("refresh_token"),
|
|
||||||
idToken: text("id_token"),
|
|
||||||
accessTokenExpiresAt: timestamp("access_token_expires_at"),
|
|
||||||
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
|
|
||||||
scope: text("scope"),
|
|
||||||
password: text("password"),
|
|
||||||
createdAt: timestamp("created_at").notNull(),
|
|
||||||
updatedAt: timestamp("updated_at").notNull(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const verification = auth_schema.table("verification", {
|
|
||||||
id: text("id").primaryKey(),
|
|
||||||
identifier: text("identifier").notNull(),
|
|
||||||
value: text("value").notNull(),
|
|
||||||
expiresAt: timestamp("expires_at").notNull(),
|
|
||||||
createdAt: timestamp("created_at"),
|
|
||||||
updatedAt: timestamp("updated_at"),
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,25 @@ export const auth = betterAuth({
|
||||||
verification: verification
|
verification: verification
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
rateLimit: {
|
||||||
|
window: 60,
|
||||||
|
max: 100,
|
||||||
|
storage: "database",
|
||||||
|
modelName: "rateLimit", //optional by default "rateLimit" is used
|
||||||
|
customRules: {
|
||||||
|
"/sign-in/email": {
|
||||||
|
window: 3600 * 12,
|
||||||
|
max: 10,
|
||||||
|
},
|
||||||
|
"/two-factor/*": async (request) => {
|
||||||
|
// custom function to return rate limit window and max
|
||||||
|
return {
|
||||||
|
window: 3600 * 12,
|
||||||
|
max: 10,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
emailAndPassword: {
|
emailAndPassword: {
|
||||||
enabled: true, // If you want to use email and password auth
|
enabled: true, // If you want to use email and password auth
|
||||||
requireEmailVerification: false,
|
requireEmailVerification: false,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue