fix: handle Docker build placeholder env vars in Supabase clients and VAPID init
Docker builds use __NEXT_PUBLIC_*__ sentinel values that get replaced at runtime by docker-entrypoint.sh. These placeholders caused build failures: - Supabase client constructor rejected invalid URL during page prerendering - web-push VAPID init rejected invalid key format Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
b5b004509d
commit
3909f23725
@@ -18,7 +18,11 @@ const vapidPublicKey = process.env.NEXT_PUBLIC_VAPID_PUBLIC_KEY
|
||||
const vapidPrivateKey = process.env.VAPID_PRIVATE_KEY
|
||||
const vapidSubject = process.env.VAPID_SUBJECT || 'mailto:support@erp-base.se'
|
||||
|
||||
if (vapidPublicKey && vapidPrivateKey) {
|
||||
if (
|
||||
vapidPublicKey &&
|
||||
vapidPrivateKey &&
|
||||
!vapidPublicKey.startsWith('__')
|
||||
) {
|
||||
webpush.setVapidDetails(vapidSubject, vapidPublicKey, vapidPrivateKey)
|
||||
}
|
||||
|
||||
|
||||
+10
-2
@@ -1,8 +1,16 @@
|
||||
import { createBrowserClient } from '@supabase/ssr'
|
||||
|
||||
// During Docker builds, NEXT_PUBLIC_* vars are placeholder sentinels
|
||||
// (e.g. __NEXT_PUBLIC_SUPABASE_URL__) that get replaced at runtime by
|
||||
// docker-entrypoint.sh. Provide a dummy URL so the client constructor
|
||||
// doesn't throw during Next.js static page generation.
|
||||
const url = process.env.NEXT_PUBLIC_SUPABASE_URL!
|
||||
const key = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
|
||||
const isBuildPlaceholder = url.startsWith('__')
|
||||
|
||||
export function createClient() {
|
||||
return createBrowserClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
|
||||
isBuildPlaceholder ? 'https://placeholder.supabase.co' : url,
|
||||
isBuildPlaceholder ? 'placeholder' : key
|
||||
)
|
||||
}
|
||||
|
||||
+11
-3
@@ -1,12 +1,20 @@
|
||||
import { createServerClient } from '@supabase/ssr'
|
||||
import { cookies } from 'next/headers'
|
||||
|
||||
// During Docker builds, NEXT_PUBLIC_* vars are placeholder sentinels
|
||||
// replaced at runtime by docker-entrypoint.sh.
|
||||
const url = process.env.NEXT_PUBLIC_SUPABASE_URL!
|
||||
const key = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
|
||||
const isBuildPlaceholder = url?.startsWith('__')
|
||||
const safeUrl = isBuildPlaceholder ? 'https://placeholder.supabase.co' : url
|
||||
const safeKey = isBuildPlaceholder ? 'placeholder' : key
|
||||
|
||||
export async function createClient() {
|
||||
const cookieStore = await cookies()
|
||||
|
||||
return createServerClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
||||
safeUrl,
|
||||
safeKey,
|
||||
{
|
||||
cookies: {
|
||||
getAll() {
|
||||
@@ -32,7 +40,7 @@ export async function createServiceClient() {
|
||||
const cookieStore = await cookies()
|
||||
|
||||
return createServerClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
safeUrl,
|
||||
process.env.SUPABASE_SERVICE_ROLE_KEY!,
|
||||
{
|
||||
cookies: {
|
||||
|
||||
Reference in New Issue
Block a user