-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passing Cookies #2
Comments
Cookies are just headers, library passes them through, so should work out of the box. If not, check if you see set-cookie header in response in devtools. And make sure you use Nextjs cookie helper on server side to set them on response. I think the simplest way would be to do it in API handler (aka API route). Let me know what you will see there. |
I've been trying to do exactly that. Works fine in dev, but as soon as launching a built app the cookies do not get passed. Can you confirm it works for you? |
I managed to trace the issue back to the partition not working when using the interceptor and thus no persistent session.
When setting the window to have partition:
|
@jamcalli I have researched the problem and looks like Electron simply ignores cookies in the interceptor. Some bugs for reference: electron/electron#30717 and electron/electron#39525. So I have reimplemented the intercept using non-deprecated Make sure to check out readme as API has changed, you now need to provide session to |
@kirill-konshin thanks for looking into this. The cookies still do not work though, and now I am getting crashes every time I try and interact with cookies. For example, one of my components stores states in a cookie, and I get the following error:
My component sets a cookie like so:
I also use the interceptor in dev mode where electron will allow localhost and partitions (to test cross-process functionality), and with the partition set, everything works as expected with the previous version. Something to do with localhost, instead of the typical File:// when running in production causes the error:
If I set the window to launch the standalone/index.html, the partition works, but it throws off all the pathing within the interceptor. |
The dev mode simply assumes you run Next.js as a server, in the usual way, so things work as expected. For production mode, there is no server running, and no ports are open. In prod mode library does some magic to convert cookies from Electron cookie storage to Next.js and back.
Using invalid characters, like a colon, can cause cookies to be ignored or lead to errors in some HTTP clients and servers. Browsers tend to be forgiving with certain non-standard or invalid characters in cookie names, including colons, as part of a broader principle of “robustness” in web technologies. So just use dashes, maybe? |
That's all fair and true. I am just using the unmodified shadcn dashboard component to test, where that cookie is set. I would assume that the package should work with those components, given their popularity. Perhaps a regex to for compliance? |
Well the regex in On the other hand tomorrow I will try to find a more relaxed way (for instance, downgrade to 0.6.0). There's a ticket in |
I have downgraded the |
I can confirm that everything is working more or less as I would expect. Really appreciate your commitment to making this work. The cookies show when explicitly set in the response, and the partition issues related to the session are also resolved. I like to control routing using cookies from iron-session, in conjunction with middleware, and they are still not being set. For example:
Does not result in any cookies being set. A small caveat that will be completely circumvented when next middleware can run in a node runtime. Cheers and thanks again. |
I have tried this lib, and works as expected. Few corrections though: in Next.js 15 you need to const session = await getIronSession(await cookies(), { password, cookieName: 'iron' });
session['username'] = 'Alison';
await session.save(); I've created a ticket for them: vvo/iron-session#869 I can see cookies being set in Electron's storage, and upon next reload I see them in Next.js Route Handler. Keep in mind that Iron cookie is httpOnly, so you won't see it in frontend. |
I have published |
I can confirm everything is working exactly as expected. Thanks so much. |
Perfect, thanks for reporting! It’s impossible to predict all potential use cases, so your feedback is extremely valuable. |
One final unrelated question. Do you know if you configure next image cache optimization directory? Asar is read only and ideally I would set the cache to the user Data dir but I'm not sure that's possible. Or is asar not recommended? |
Please create a separate issue for this and I will think on it. Should be doable. ASAR is recommended, but not required. |
jshttp/cookie#191 version 1.0.2 has been released with relaxed set of cookie-related checks. It works properly now, I have published 0.2.3 with this change. |
Great package.
Working very well.
I have a question though. How do you set cookies from localhost in production? I have been banging my head against this for a while so thought I would see if you knew the solution.
Cheers.
The text was updated successfully, but these errors were encountered: