Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

How to access cookies within +layout.js in SvelteKit?

$
0
0

I want to access cookies in the load function within +layout.js. I want to be able to make my header/nav in the template show "login/signup" in the nav if there is not a jwt saved in cookies, but show "logout" if there is.

Below is my +layout.js. I expect this to access cookies like it does in the exact same code in my +page.server.js file. Instead, I get the error "Cannot read properties of undefined (reading 'get')"

export function load({ cookies }) {    return {        jwt: cookies.get("jwt")    }}

Viewing all articles
Browse latest Browse all 1541

Trending Articles