fix: resolve internal docker hostnames to client window location hostname in browser context
All checks were successful
Staging Build / build (push) Successful in 1m49s
All checks were successful
Staging Build / build (push) Successful in 1m49s
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { createBrowserClient } from "@supabase/ssr";
|
||||
import { resolveSupabaseUrl } from "../utils";
|
||||
|
||||
export function createClient() {
|
||||
const supabaseUrl = process.env.SUPABASE_URL || process.env.NEXT_PUBLIC_SUPABASE_URL;
|
||||
const supabaseAnonKey = process.env.SUPABASE_ANON_KEY || process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
|
||||
|
||||
return createBrowserClient(
|
||||
supabaseUrl!,
|
||||
resolveSupabaseUrl(supabaseUrl)!,
|
||||
supabaseAnonKey!,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createServerClient } from "@supabase/ssr";
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
import { hasEnvVars } from "../utils";
|
||||
import { hasEnvVars, resolveSupabaseUrl } from "../utils";
|
||||
|
||||
export async function updateSession(request: NextRequest) {
|
||||
let supabaseResponse = NextResponse.next({
|
||||
@@ -17,7 +17,7 @@ export async function updateSession(request: NextRequest) {
|
||||
const supabaseAnonKey = process.env.SUPABASE_ANON_KEY || process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
|
||||
|
||||
const supabase = createServerClient(
|
||||
supabaseUrl!,
|
||||
resolveSupabaseUrl(supabaseUrl)!,
|
||||
supabaseAnonKey!,
|
||||
{
|
||||
cookies: {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createServerClient } from "@supabase/ssr";
|
||||
import { cookies } from "next/headers";
|
||||
import { resolveSupabaseUrl } from "../utils";
|
||||
|
||||
/**
|
||||
* Especially important if using Fluid compute: Don't put this client in a
|
||||
@@ -13,7 +14,7 @@ export async function createClient() {
|
||||
const supabaseAnonKey = process.env.SUPABASE_ANON_KEY || process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
|
||||
|
||||
return createServerClient(
|
||||
supabaseUrl!,
|
||||
resolveSupabaseUrl(supabaseUrl)!,
|
||||
supabaseAnonKey!,
|
||||
{
|
||||
cookies: {
|
||||
|
||||
@@ -11,3 +11,21 @@ export const hasEnvVars =
|
||||
(process.env.SUPABASE_ANON_KEY ||
|
||||
process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY ||
|
||||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY);
|
||||
|
||||
export function resolveSupabaseUrl(url: string | undefined): string | undefined {
|
||||
if (!url) return url;
|
||||
if (typeof window !== 'undefined') {
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
if (parsed.hostname === 'supabase-kong' || parsed.hostname === 'kong') {
|
||||
parsed.hostname = window.location.hostname;
|
||||
return parsed.toString().replace(/\/$/, '');
|
||||
}
|
||||
} catch {
|
||||
return url
|
||||
.replace('//supabase-kong', `//${window.location.hostname}`)
|
||||
.replace('//kong', `//${window.location.hostname}`);
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user