feat: initial setup of database and auth

This commit is contained in:
2026-04-25 12:31:42 +08:00
parent 78079779c9
commit 18888eb57e
3 changed files with 74 additions and 616 deletions
+15
View File
@@ -0,0 +1,15 @@
import { createAuthClient } from 'better-auth/client'
import { adminClient, emailOTPClient, lastLoginMethodClient } from 'better-auth/client/plugins'
import { passkeyClient } from '@better-auth/passkey/client'
export const authClient = createAuthClient({
baseURL: process.env.NEXT_PUBLIC_BASE_URL || "https://localhost:3000",
plugins: [
emailOTPClient(),
passkeyClient(),
lastLoginMethodClient(),
adminClient()
]
})
export const { signIn, signOut, signUp, getSession, useSession } = authClient
+59
View File
@@ -0,0 +1,59 @@
import { betterAuth } from 'better-auth'
import { admin, emailOTP, lastLoginMethod } from 'better-auth/plugins'
import { passkey } from '@better-auth/passkey'
import { drizzleAdapter } from '@better-auth/drizzle-adapter'
import { db } from '@/lib/db/index'
export const auth = betterAuth({
experimental: { joins: true },
database: drizzleAdapter(db, {
provider: 'pg'
}),
plugins: [
emailOTP({
async sendVerificationOTP({ email, otp, type }) {
if (type === 'sign-in') {
// TODO: send the OTP to the user's email address
} else if (type === 'email-verification') {
// TODO: send the OTP to the user's email address for email verification
} else {
// TODO: send the OTP to the user's email address for password reset
}
}
}),
passkey(),
lastLoginMethod(),
admin()
],
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID || "",
clientSecret: process.env.GOOGLE_CLIENT_SECRET || "",
},
discord: {
clientId: process.env.DISCORD_CLIENT_ID || "",
clientSecret: process.env.DISCORD_CLIENT_SECRET || "",
},
},
trustedOrigins: [process.env.NEXT_PUBLIC_BASE_URL || "https://localhost:3000"],
rateLimit: {
enabled: true,
window: 60,
max: 100
},
session: {
expiresIn: 60 * 60 * 24 * 7,
updateAge: 60 * 60 * 24,
cookieCache: {
enabled: true,
maxAge: 15 * 60,
},
},
account: {
accountLinking: {
enabled: true,
trustedProviders: ['google', 'discord'],
allowDifferentEmails: true
}
}
})