#cookie.parse is not returning my cookie

1 messages · Page 1 of 1 (latest)

clever kite
#

I'm having an issue where when I try to get my cookie using myCookie.parse(request.headers.get("cookie")) it is not finding my requested cookie. When I log out the headers I can see it in the cookie string but the function just keeps bringing back null. This only seems to happen after I set multiple cookies as the same time using the following code.

const cookie = locationCookie.serialize(locationData)
const headers = new Headers();
if (auth?.cookie) headers.append("Set-Cookie", auth.cookie);
headers.append("Set-Cookie", cookie);

return redirect("/stores", { headers });

It's the locationCookie and I can't get later. When I set the location cookie in other actions with cookie.serialize(locationData) I'm able to pull it up in other loaders without issue. Am I doing something wrong here? Is there a different ay to set multiple cookies at the same time?

modern jasper
#

Headers supports setting multiple cookies at the same time using append. cookie.serialize however returns a promise, so make sure you await it, e.g. const cookie = await locationCookie.serialize(locationData). Not sure if this is all what's going on here, but at least in the snippet you shared, I'm thinking that locationCookie wouldn't be set correctly because of that issue.