Issue with setting session_token cookie in SvelteKit SSR

I'm experimenting with better-auth in SvelteKit SSR mode for registration and login functionality. I'm successfully getting the session_token cookie from the auth API:
const { headers, response } = await auth.api.signInEmail({
returnHeaders: true,
body: {
email,
password
}
});
const { headers, response } = await auth.api.signInEmail({
returnHeaders: true,
body: {
email,
password
}
});
This returns the cookie as a string. However, SvelteKit's setHeader method doesn't allow setting cookies directly, and the cookies object requires individual cookie properties rather than accepting a cookie string. Is there a better approach to handle this cookie setting without adding a cookie parsing dependency? I'm aware of the authClient but specifically want to experiment with SSR implementation. Thanks!
1 Reply
Budi
Budi3mo ago
I'm curious about the same. Failing to successfully implement server-side authentication so far. Did you manage to find a solution @Stephen G ? Actually I found a solution here https://discord.com/channels/1288403910284935179/1379223049332592802. Look for the SvelteCookie plugin.

Did you find this page helpful?