This commit is contained in:
hailin 2025-05-21 16:33:42 +08:00
parent cf6b20f4a5
commit e041d41945
1 changed files with 17 additions and 6 deletions

View File

@ -45,15 +45,26 @@ export default async function Login({
.eq("is_home", true) .eq("is_home", true)
.maybeSingle(); .maybeSingle();
// Define the clearCookies function // Define the clearCookies function for server-side execution
const clearCookies = async () => { const clearCookies = async () => {
const storedUrl = localStorage.getItem("supabaseUrl"); // From request headers or environment variables
if (storedUrl) { let hosturl: string | undefined;
await fetch(`${storedUrl}/api/clearcookies`, {
// Option 1: Get host from request headers (useful for dynamic requests)
const hostHeader = req.headers.get('host');
if (hostHeader) {
hosturl = `http://${hostHeader}`; // Construct full URL
} else {
// Option 2: Use environment variable as fallback
hosturl = process.env.SUPABASE_URL; // Ensure you have this set up in your environment variables
}
if (hosturl) {
await fetch(`${hosturl}/api/clearcookies`, {
method: "POST", method: "POST",
}); });
} else { } else {
console.error("Supabase URL is not stored in localStorage"); console.error("Host URL is not available");
} }
}; };