This commit is contained in:
parent
9b8b705e97
commit
1e470bf7b5
|
|
@ -93,27 +93,24 @@
|
||||||
// )
|
// )
|
||||||
|
|
||||||
|
|
||||||
// lib/supabase/browser-client.ts
|
|
||||||
|
|
||||||
import { createBrowserClient } from "@supabase/ssr"
|
import { createBrowserClient } from "@supabase/ssr"
|
||||||
import { Database } from "@/supabase/types"
|
import { Database } from "@/supabase/types"
|
||||||
|
|
||||||
let supabaseUrl = "http://localhost:8000"
|
let supabaseUrl = "http://localhost:8000"
|
||||||
|
|
||||||
// ✅ 服务端逻辑:使用 require 避免静态引入
|
|
||||||
if (typeof window === "undefined") {
|
if (typeof window === "undefined") {
|
||||||
try {
|
try {
|
||||||
const { getRuntimeEnvSSR } = require("@/lib/runtime-env/server")
|
const mod = require("../runtime-env/server") // ✅ 动态加载,避免 headers 被编译期扫描
|
||||||
const envUrl = getRuntimeEnvSSR("SUPABASE_URL")
|
const envUrl = mod.getRuntimeEnvSSR?.("SUPABASE_URL")
|
||||||
if (envUrl) {
|
if (envUrl) {
|
||||||
supabaseUrl = envUrl
|
supabaseUrl = envUrl
|
||||||
console.log("[SSR] SUPABASE_URL:", supabaseUrl)
|
console.log("[SSR] SUPABASE_URL:", supabaseUrl)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("⚠️ Failed to load runtime env on SSR", err)
|
console.error("❌ SSR runtime-env load failed:", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// ✅ 客户端逻辑
|
// ✅ CSR 环境:从 window 或 localStorage 获取
|
||||||
const runtimeEnv = (window as any).RUNTIME_ENV
|
const runtimeEnv = (window as any).RUNTIME_ENV
|
||||||
const envUrl = runtimeEnv?.SUPABASE_URL
|
const envUrl = runtimeEnv?.SUPABASE_URL
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue