You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
breaking: require path when setting/deleting/serializing cookies (#11240)
* resolve empty string correctly
* require path when setting/deleting/serializing cookies
* update types and tests
* test for ""
* changeset
* fix
* fix
* lint
* fix
* fix
* fix
* update docs
* only resolve same-domain paths
* this is out of date
---------
Co-authored-by: Rich Harris <[email protected]>
Copy file name to clipboardExpand all lines: documentation/docs/20-core-concepts/20-load.md
-2
Original file line number
Diff line number
Diff line change
@@ -283,8 +283,6 @@ For example, if SvelteKit is serving my.domain.com:
283
283
284
284
Other cookies will not be passed when `credentials: 'include'` is set, because SvelteKit does not know which domain which cookie belongs to (the browser does not pass this information along), so it's not safe to forward any of them. Use the [handleFetch hook](hooks#server-hooks-handlefetch) to work around it.
285
285
286
-
> When setting cookies, be aware of the `path` property. By default, the `path` of a cookie is the current pathname. If you for example set a cookie at page `admin/user`, the cookie will only be available within the `admin` pages by default. In most cases you likely want to set `path` to `'/'` to make the cookie available throughout your app.
287
-
288
286
## Headers
289
287
290
288
Both server and universal `load` functions have access to a `setHeaders` function that, when running on the server, can set headers for the response. (When running in the browser, `setHeaders` has no effect.) This is useful if you want the page to be cached, for example:
Copy file name to clipboardExpand all lines: packages/kit/src/exports/public.d.ts
+14-6
Original file line number
Diff line number
Diff line change
@@ -212,34 +212,42 @@ export interface Cookies {
212
212
*
213
213
* The `httpOnly` and `secure` options are `true` by default (except on http://localhost, where `secure` is `false`), and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP. The `sameSite` option defaults to `lax`.
214
214
*
215
-
* By default, the `path` of a cookie is the 'directory' of the current pathname. In most cases you should explicitly set `path: '/'` to make the cookie available throughout your app.
215
+
* You must specify a `path` for the cookie. In most cases you should explicitly set `path: '/'` to make the cookie available throughout your app. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children
216
216
* @param name the name of the cookie
217
217
* @param value the cookie value
218
218
* @param opts the options, passed directly to `cookie.serialize`. See documentation [here](https://github.com./jshttp/cookie#cookieserializename-value-options)
* Deletes a cookie by setting its value to an empty string and setting the expiry date in the past.
224
228
*
225
-
* By default, the `path` of a cookie is the 'directory' of the current pathname. In most cases you should explicitly set `path: '/'` to make the cookie available throughout your app.
229
+
* You must specify a `path` for the cookie. In most cases you should explicitly set `path: '/'` to make the cookie available throughout your app. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children
226
230
* @param name the name of the cookie
227
231
* @param opts the options, passed directly to `cookie.serialize`. The `path` must match the path of the cookie you want to delete. See documentation [here](https://github.com./jshttp/cookie#cookieserializename-value-options)
* Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response.
233
237
*
234
238
* The `httpOnly` and `secure` options are `true` by default (except on http://localhost, where `secure` is `false`), and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP. The `sameSite` option defaults to `lax`.
235
239
*
236
-
* By default, the `path` of a cookie is the current pathname. In most cases you should explicitly set `path: '/'` to make the cookie available throughout your app.
240
+
* You must specify a `path` for the cookie. In most cases you should explicitly set `path: '/'` to make the cookie available throughout your app. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children
237
241
*
238
242
* @param name the name of the cookie
239
243
* @param value the cookie value
240
244
* @param opts the options, passed directly to `cookie.serialize`. See documentation [here](https://github.com./jshttp/cookie#cookieserializename-value-options)
0 commit comments