frontend fix: Cookie passthrough
This commit is contained in:
@@ -5,7 +5,7 @@ import { fail, redirect } from "@sveltejs/kit";
|
||||
export async function load({ locals }) {
|
||||
// redirect user if not logged in
|
||||
if (!locals.user) {
|
||||
throw redirect(302, `/auth/login?next=/auth/logout`);
|
||||
throw redirect(302, `/auth/login?next=/`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,9 +34,24 @@ export const actions = {
|
||||
return fail(400, { errors: errors });
|
||||
}
|
||||
|
||||
// The server should clear the cookie, so we don't need to handle it here
|
||||
// eat the cookie
|
||||
cookies.delete("jwt", { path: "/" });
|
||||
|
||||
// The server should clear the cookie, so we don't need to handle it here
|
||||
// Just check if the cookie is cleared in the response
|
||||
const setCookieHeader = res.headers.get("set-cookie");
|
||||
if (!setCookieHeader || !setCookieHeader.includes("jwt=;")) {
|
||||
console.error("JWT cookie not cleared in response");
|
||||
return fail(500, {
|
||||
errors: [
|
||||
{
|
||||
error: "Server error: Failed to clear authentication token",
|
||||
id: Date.now(),
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
// redirect the user
|
||||
throw redirect(302, "/auth/login");
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user