I'm fairly new to Svelte Kit and I am trying to set a cookie in the load function of my +page.server.js.
Here is the code I have tried:
export const load = ({ cookies }) => {
cookies.set("username", "foo", {
secure : false,
maxAge : 60 * 60 * 24 * 7
})
}
How ever the cookie doesn't get set and I verify this by opening the Application panel of the developer console to check if the cookie has been made.
I also don't get any errors for performing this action.
I can however get previously existing cookies inside the load function without any problems,
using cookies.get().

After a lot of frustration and agony, I have figured out why my cookies wouldn't get set.
I am using pocketbase for authentication and I am handling the authentication in my
hooks.server.jsin this way:The handle function runs on every request to the server and you can read more about it in the official documentation of SvelteKit: https://kit.svelte.dev/docs/hooks#server-hooks-handle
Now the issue is in this specific line of code:
Here I'm using
response.headers.set()to set my authentication cookie which is a problem as it wipes out the entire cookie list and only sets the authentication cookieIn reality I should have been doing this:
This appends the authentication cookie into the cookie list instead of wiping the entire thing
After making the changes, I got the desired result: