0.0.5 • Published 10 months ago

sveltekit-fullstack-cookies v0.0.5

Weekly downloads
-
License
-
Repository
-
Last release
10 months ago

Get the User's Cookies from both the server and the client with one function

I don't know why this is not built into sveltekit.

Setup

hooks.server.ts:

import { fullstackCookiesHandle } from "sveltekit-fullstack-cookies"

export const handle = sequence(fullstackCookiesHandle /* ... */)

Use

The getCookies() method returns an object containing the cookies (keys-value pairs).

1. Make all cookies available globally with $page.data.cookies (reactive):

root +layout.ts:

import { getCookies } from "sveltekit-fullstack-cookies"

export const load = async () => {
	/* ... */
	return {
		cookies: await getCookies(),
		/* ... */
	}
}

To reload the cookies, call invalidateAll() (imported from @app/navigation)

2. Get the current cookies at one specific moment:

import { getCookies } from "sveltekit-fullstack-cookies"

const cookies = await getCookies()

Additionally, you can provide a fallback for prerendering:

await getCookies({ exampleCookie: "example value" })
0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago