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 -24
View File
@@ -1,32 +1,11 @@
import { createClient } from '@supabase/supabase-js'
import type { Database } from './types'
let _supabase: ReturnType<typeof createClient<Database>> | null = null
function getSupabase() {
if (!_supabase) {
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY
if (!supabaseUrl || !supabaseAnonKey) {
throw new Error(
'Missing required environment variables: NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY. Please configure them in your deployment settings or .env.local file.'
)
}
_supabase = createClient<Database>(supabaseUrl, supabaseAnonKey)
}
return _supabase
}
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
/**
* Supabase client for client-side use with anon key
* Uses Row Level Security (RLS) policies
*
* Initialized lazily to avoid requiring env vars at build time
*/
export const supabase = new Proxy({} as ReturnType<typeof createClient<Database>>, {
get(_target, prop) {
return Reflect.get(getSupabase(), prop)
},
})
export const supabase = createClient<Database>(supabaseUrl, supabaseAnonKey)
+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
+6 -27
View File
@@ -1,38 +1,17 @@
import { createClient } from '@supabase/supabase-js'
import type { Database } from './types'
let _supabaseAdmin: ReturnType<typeof createClient<Database>> | null = null
function getSupabaseAdmin() {
if (!_supabaseAdmin) {
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
const supabaseServiceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY
if (!supabaseUrl || !supabaseServiceRoleKey) {
throw new Error(
'Missing required environment variables: NEXT_PUBLIC_SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY. Please configure them in your deployment settings or .env.local file.'
)
}
_supabaseAdmin = createClient<Database>(supabaseUrl, supabaseServiceRoleKey, {
auth: {
persistSession: false,
autoRefreshToken: false,
},
})
}
return _supabaseAdmin
}
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!
const supabaseServiceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY!
/**
* Supabase client for server-side use with service role key
* Bypasses Row Level Security (RLS) - use with caution
* Always filter by user_id to enforce permissions
*
* Initialized lazily to avoid requiring env vars at build time
*/
export const supabaseAdmin = new Proxy({} as ReturnType<typeof createClient<Database>>, {
get(_target, prop) {
return Reflect.get(getSupabaseAdmin(), prop)
export const supabaseAdmin = createClient<Database>(supabaseUrl, supabaseServiceRoleKey, {
auth: {
persistSession: false,
autoRefreshToken: false,
},
})