Kehvyn
Kehvyn
SSolidJS
Created by Kehvyn on 2/24/2025 in #support
Debugging "Error: Can't render headers after they are sent to the client."
I'm trying to figure out how to debug the above error. This happens whenever I hit "Sign Out" on my Supabase Auth + Solid Start project. It's triggered by setCookie in my Supabase server client initialization function. I'm not sure where to start on this one. I've been able to confirm that the problematic cookie is the Supabase Auth Token by logging out the name and the value when it errors: { name: 'sb-<project>-auth-token', value: '' } Since the code is fairly small here, I'm just going to post it in full. The HTML
<form action={signOutAction} method="post">
<button formAction={signOutAction} class="border-b-2 mx-1.5 sm:mx-6" type="submit">Sign Out</button>
</form>
<form action={signOutAction} method="post">
<button formAction={signOutAction} class="border-b-2 mx-1.5 sm:mx-6" type="submit">Sign Out</button>
</form>
signOutAction:
export const signOutAction = action(async () => {
"use server";
const event = getRequestEvent()!
const supabase = createServerClient(event);
await supabase.auth.signOut();
return redirect("/sign-in");
}, "signOutAction");
export const signOutAction = action(async () => {
"use server";
const event = getRequestEvent()!
const supabase = createServerClient(event);
await supabase.auth.signOut();
return redirect("/sign-in");
}, "signOutAction");
createServerClient:
import { createServerClient as _createServerClient } from "@supabase/ssr";
import { RequestEvent } from "solid-js/web";
import { parseCookies, setCookie } from "vinxi/http";

export const createServerClient = (event: RequestEvent) => {
return _createServerClient(
process.env.VITE_SUPABASE_URL!,
process.env.VITE_SUPABASE_ANON_KEY!,
{
cookies: {
getAll() {
return Object.entries(parseCookies(event.nativeEvent)).map(([name, value]) => ({ name, value }));
},
setAll(cookiesToSet: { name: string, value: string }[]) {
cookiesToSet.forEach(({ name, value }: { name: string, value: string }) => {
setCookie(event.nativeEvent, name, value)
});
},
},
},
);
};
import { createServerClient as _createServerClient } from "@supabase/ssr";
import { RequestEvent } from "solid-js/web";
import { parseCookies, setCookie } from "vinxi/http";

export const createServerClient = (event: RequestEvent) => {
return _createServerClient(
process.env.VITE_SUPABASE_URL!,
process.env.VITE_SUPABASE_ANON_KEY!,
{
cookies: {
getAll() {
return Object.entries(parseCookies(event.nativeEvent)).map(([name, value]) => ({ name, value }));
},
setAll(cookiesToSet: { name: string, value: string }[]) {
cookiesToSet.forEach(({ name, value }: { name: string, value: string }) => {
setCookie(event.nativeEvent, name, value)
});
},
},
},
);
};
This is part of a whole template that I've been working on, so I can also submit the whole thing to GitHub in PR form. 🙂
18 replies