32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { clsx, type ClassValue } from "clsx";
|
|
import { twMerge } from "tailwind-merge";
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs));
|
|
}
|
|
|
|
// This check can be removed, it is just for tutorial purposes
|
|
export const hasEnvVars =
|
|
(process.env.SUPABASE_URL || process.env.NEXT_PUBLIC_SUPABASE_URL) &&
|
|
(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;
|
|
}
|