-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Description
Describe the problem
(Sorry if this is a know issue/topic, I searched by couldn't find anything.)
Cannot remove a cookie using cookies.delete on a path (say src/routes/foo/+page.server.ts) if the cookie was made at another path (say src/routes/+layout.server.ts) since path gets set to / and calling delete in /foo will pass path: "/foo".
Describe the proposed solution
Add an optional argument paramter to .delete to accept options the same as set():
cookies.delete("auth_token", { path: "/" })Alternatives considered
Using set to empty the cookie but that is a hack:
cooklies.set("auth_token", "", { path: / })Importance
would make my life easier
Additional Information
// src/routes/logout/+page.server.ts
import { redirect } from "@sveltejs/kit";
import type { PageServerLoad } from "./$types";
export const load: PageServerLoad = async (event) => {
event.cookies.delete("auth_token");
throw redirect(302, "/");
};// src/routes/login/+page.server.ts
import { invalid, redirect } from "@sveltejs/kit";
import type { Actions } from "./$types";
export const actions: Actions = {
async default(event) {
// Some auth logic here...
event.cookies.set("auth_token", token, { path: "/" });
throw redirect(302, "/dashboard");
},
};Metadata
Metadata
Assignees
Labels
No labels