diff --git a/shop/components/NavbarClient.tsx b/shop/components/NavbarClient.tsx index d0c9b47..e7ecce6 100644 --- a/shop/components/NavbarClient.tsx +++ b/shop/components/NavbarClient.tsx @@ -8,6 +8,7 @@ import { type User } from "@supabase/supabase-js"; import { Rocket, Menu, X, User as UserIcon, LogOut } from "lucide-react"; import { Button } from "@/components/ui/button"; import { signOut } from "@/lib/actions/auth"; +import { resolveSupabaseUrl } from "@/lib/utils"; interface NavbarClientProps { user: User | null; @@ -25,25 +26,9 @@ export function NavbarClient({ user, role = "partner" }: NavbarClientProps) { 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; - // Supabase URL Auflösung inline - let resolvedUrl = supabaseUrl; - if (resolvedUrl && typeof window !== "undefined") { - try { - const parsed = new URL(resolvedUrl); - if (parsed.hostname === "supabase-kong" || parsed.hostname === "kong") { - parsed.hostname = window.location.hostname; - resolvedUrl = parsed.toString().replace(/\/$/, ""); - } - } catch { - resolvedUrl = resolvedUrl - .replace("//supabase-kong", `//${window.location.hostname}`) - .replace("//kong", `//${window.location.hostname}`); - } - } - // Browser Client inline erstellen const supabase = createBrowserClient( - resolvedUrl!, + resolveSupabaseUrl(supabaseUrl)!, supabaseAnonKey!, { cookieOptions: { diff --git a/shop/components/admin/logout-menu-item.tsx b/shop/components/admin/logout-menu-item.tsx index 446236c..dbffe2e 100644 --- a/shop/components/admin/logout-menu-item.tsx +++ b/shop/components/admin/logout-menu-item.tsx @@ -4,6 +4,7 @@ import { signOut } from "@/lib/actions/auth"; import { useRouter } from "next/navigation"; import { LogOut } from "lucide-react"; import { createBrowserClient } from "@supabase/ssr"; +import { resolveSupabaseUrl } from "@/lib/utils"; export function AdminLogoutButton() { const router = useRouter(); @@ -12,25 +13,9 @@ export function AdminLogoutButton() { 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; - // Supabase URL Auflösung inline - let resolvedUrl = supabaseUrl; - if (resolvedUrl && typeof window !== "undefined") { - try { - const parsed = new URL(resolvedUrl); - if (parsed.hostname === "supabase-kong" || parsed.hostname === "kong") { - parsed.hostname = window.location.hostname; - resolvedUrl = parsed.toString().replace(/\/$/, ""); - } - } catch { - resolvedUrl = resolvedUrl - .replace("//supabase-kong", `//${window.location.hostname}`) - .replace("//kong", `//${window.location.hostname}`); - } - } - // Browser Client inline erstellen const supabase = createBrowserClient( - resolvedUrl!, + resolveSupabaseUrl(supabaseUrl)!, supabaseAnonKey!, { cookieOptions: { diff --git a/shop/components/inactivity-tracker.tsx b/shop/components/inactivity-tracker.tsx index 65f7f72..832fba4 100644 --- a/shop/components/inactivity-tracker.tsx +++ b/shop/components/inactivity-tracker.tsx @@ -4,6 +4,7 @@ import { useEffect } from "react"; import { createBrowserClient } from "@supabase/ssr"; import { useRouter } from "next/navigation"; import { signOut } from "@/lib/actions/auth"; +import { resolveSupabaseUrl } from "@/lib/utils"; export function InactivityTracker() { const router = useRouter(); @@ -12,25 +13,9 @@ export function InactivityTracker() { 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; - // Supabase URL Auflösung inline - let resolvedUrl = supabaseUrl; - if (resolvedUrl && typeof window !== "undefined") { - try { - const parsed = new URL(resolvedUrl); - if (parsed.hostname === "supabase-kong" || parsed.hostname === "kong") { - parsed.hostname = window.location.hostname; - resolvedUrl = parsed.toString().replace(/\/$/, ""); - } - } catch { - resolvedUrl = resolvedUrl - .replace("//supabase-kong", `//${window.location.hostname}`) - .replace("//kong", `//${window.location.hostname}`); - } - } - // Browser Client inline erstellen const supabase = createBrowserClient( - resolvedUrl!, + resolveSupabaseUrl(supabaseUrl)!, supabaseAnonKey!, { cookieOptions: { diff --git a/shop/lib/utils.ts b/shop/lib/utils.ts index 5edc138..3de7a26 100644 --- a/shop/lib/utils.ts +++ b/shop/lib/utils.ts @@ -19,12 +19,23 @@ export function resolveSupabaseUrl(url: string | undefined): string | undefined const parsed = new URL(url); if (parsed.hostname === 'supabase-kong' || parsed.hostname === 'kong') { parsed.hostname = window.location.hostname; + parsed.protocol = window.location.protocol; + return parsed.toString().replace(/\/$/, ''); + } + + // Mitigate Mixed Content: if the site is HTTPS, force Supabase to HTTPS + if (window.location.protocol === 'https:' && parsed.protocol === 'http:') { + parsed.protocol = 'https:'; return parsed.toString().replace(/\/$/, ''); } } catch { - return url + let resolved = url .replace('//supabase-kong', `//${window.location.hostname}`) .replace('//kong', `//${window.location.hostname}`); + if (window.location.protocol === 'https:') { + resolved = resolved.replace('http://', 'https://'); + } + return resolved; } } return url;