fix magic link issue

This commit is contained in:
wass08
2026-02-11 17:09:08 +09:00
parent 64205b1077
commit 92f1c065f8
6 changed files with 129 additions and 221 deletions
+3 -30
View File
@@ -1,38 +1,11 @@
import { drizzle } from 'drizzle-orm/postgres-js'
import type { PostgresJsDatabase } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'
import * as schema from './schema'
let _db: PostgresJsDatabase<typeof schema> | null = null
let _client: ReturnType<typeof postgres> | null = null
const connectionString = process.env.POSTGRES_URL!
function getDb() {
if (!_db) {
const postgresUrl = process.env.POSTGRES_URL
const client = postgres(connectionString, { prepare: false })
if (!postgresUrl) {
throw new Error(
'Missing POSTGRES_URL environment variable. Please configure it in your deployment settings or .env.local file.',
)
}
// Create postgres connection
_client = postgres(postgresUrl)
// Create drizzle instance
_db = drizzle(_client, { schema })
}
return _db
}
/**
* Drizzle database instance
* Initialized lazily to avoid requiring env vars at build time
*/
export const db = new Proxy({} as PostgresJsDatabase<typeof schema>, {
get(_target, prop) {
return Reflect.get(getDb(), prop)
},
})
export const db = drizzle({ client, schema })
export type Database = typeof db