fix: resolve mixed content errors by synchronizing client supabase URL protocol with window location protocol
All checks were successful
Staging Build / build (push) Successful in 2m18s
All checks were successful
Staging Build / build (push) Successful in 2m18s
This commit is contained in:
@@ -8,6 +8,7 @@ import { type User } from "@supabase/supabase-js";
|
|||||||
import { Rocket, Menu, X, User as UserIcon, LogOut } from "lucide-react";
|
import { Rocket, Menu, X, User as UserIcon, LogOut } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { signOut } from "@/lib/actions/auth";
|
import { signOut } from "@/lib/actions/auth";
|
||||||
|
import { resolveSupabaseUrl } from "@/lib/utils";
|
||||||
|
|
||||||
interface NavbarClientProps {
|
interface NavbarClientProps {
|
||||||
user: User | null;
|
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 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;
|
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
|
// Browser Client inline erstellen
|
||||||
const supabase = createBrowserClient(
|
const supabase = createBrowserClient(
|
||||||
resolvedUrl!,
|
resolveSupabaseUrl(supabaseUrl)!,
|
||||||
supabaseAnonKey!,
|
supabaseAnonKey!,
|
||||||
{
|
{
|
||||||
cookieOptions: {
|
cookieOptions: {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { signOut } from "@/lib/actions/auth";
|
|||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { LogOut } from "lucide-react";
|
import { LogOut } from "lucide-react";
|
||||||
import { createBrowserClient } from "@supabase/ssr";
|
import { createBrowserClient } from "@supabase/ssr";
|
||||||
|
import { resolveSupabaseUrl } from "@/lib/utils";
|
||||||
|
|
||||||
export function AdminLogoutButton() {
|
export function AdminLogoutButton() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -12,25 +13,9 @@ export function AdminLogoutButton() {
|
|||||||
const supabaseUrl = process.env.SUPABASE_URL || process.env.NEXT_PUBLIC_SUPABASE_URL;
|
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;
|
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
|
// Browser Client inline erstellen
|
||||||
const supabase = createBrowserClient(
|
const supabase = createBrowserClient(
|
||||||
resolvedUrl!,
|
resolveSupabaseUrl(supabaseUrl)!,
|
||||||
supabaseAnonKey!,
|
supabaseAnonKey!,
|
||||||
{
|
{
|
||||||
cookieOptions: {
|
cookieOptions: {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useEffect } from "react";
|
|||||||
import { createBrowserClient } from "@supabase/ssr";
|
import { createBrowserClient } from "@supabase/ssr";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { signOut } from "@/lib/actions/auth";
|
import { signOut } from "@/lib/actions/auth";
|
||||||
|
import { resolveSupabaseUrl } from "@/lib/utils";
|
||||||
|
|
||||||
export function InactivityTracker() {
|
export function InactivityTracker() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -12,25 +13,9 @@ export function InactivityTracker() {
|
|||||||
const supabaseUrl = process.env.SUPABASE_URL || process.env.NEXT_PUBLIC_SUPABASE_URL;
|
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;
|
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
|
// Browser Client inline erstellen
|
||||||
const supabase = createBrowserClient(
|
const supabase = createBrowserClient(
|
||||||
resolvedUrl!,
|
resolveSupabaseUrl(supabaseUrl)!,
|
||||||
supabaseAnonKey!,
|
supabaseAnonKey!,
|
||||||
{
|
{
|
||||||
cookieOptions: {
|
cookieOptions: {
|
||||||
|
|||||||
@@ -19,12 +19,23 @@ export function resolveSupabaseUrl(url: string | undefined): string | undefined
|
|||||||
const parsed = new URL(url);
|
const parsed = new URL(url);
|
||||||
if (parsed.hostname === 'supabase-kong' || parsed.hostname === 'kong') {
|
if (parsed.hostname === 'supabase-kong' || parsed.hostname === 'kong') {
|
||||||
parsed.hostname = window.location.hostname;
|
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(/\/$/, '');
|
return parsed.toString().replace(/\/$/, '');
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
return url
|
let resolved = url
|
||||||
.replace('//supabase-kong', `//${window.location.hostname}`)
|
.replace('//supabase-kong', `//${window.location.hostname}`)
|
||||||
.replace('//kong', `//${window.location.hostname}`);
|
.replace('//kong', `//${window.location.hostname}`);
|
||||||
|
if (window.location.protocol === 'https:') {
|
||||||
|
resolved = resolved.replace('http://', 'https://');
|
||||||
|
}
|
||||||
|
return resolved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return url;
|
return url;
|
||||||
|
|||||||
Reference in New Issue
Block a user