Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,153,437 members, 7,819,606 topics. Date: Monday, 06 May 2024 at 06:58 PM |
Nairaland Forum / Science/Technology / Programming / Why Is Heroku Not Setting My Cookie (1506 Views)
What Other Alternative To Heroku / Help With Node.js App Deployment To Heroku (Solved!!!) / Help On Deployment On Heroku (2) (3) (4)
Why Is Heroku Not Setting My Cookie by chukwuebuka65(m): 12:50pm On Sep 03, 2022 |
I have a backend writing in Nodejs and express that i deployed to heroku that is using free dyno hours. I am using cookies to keep users logged in. But heroku is not setting my cookies in the browser. Why is that? 1 Like |
Re: Why Is Heroku Not Setting My Cookie by arejibadz(m): 3:07pm On Sep 03, 2022 |
chukwuebuka65:did you set your config , try hosting your keys 2 Likes |
Re: Why Is Heroku Not Setting My Cookie by chukwuebuka65(m): 3:45pm On Sep 03, 2022 |
arejibadz: What keys? And what options of the config? 1 Like |
Re: Why Is Heroku Not Setting My Cookie by arejibadz(m): 3:55pm On Sep 03, 2022 |
chukwuebuka65:I'm sure you stored your key in your .env You have set your whatever your key is in your .env file with Heroku Run the following command on your cmd heroku config:set SECRET=1992992292992929292929 Or you can just go on heroku and put it in your settings 3 Likes
|
Re: Why Is Heroku Not Setting My Cookie by chukwuebuka65(m): 4:49pm On Sep 03, 2022 |
arejibadz: I did that. That’s not the problem. From stackoverflow I am getting a hint about heroku load balancer terminating ssl before request reach my app. Therefore my express seeing that the connection is not over ssl refuses to set the secure attribute of the cookie. And because the samesite attribute is set to none , the browser will not save the cookie because the secure attribute is not there. I think my problem now is how to tell my express app to set the secure attribute of the cookie whether over ssl or not. Can you help with that? |
Re: Why Is Heroku Not Setting My Cookie by jbreezy: 7:13pm On Sep 03, 2022 |
chukwuebuka65:If you are using cookier-parser middleware, inside the middleware, include this {secure: true, samesite:”none”}… It will solve your problem |
Re: Why Is Heroku Not Setting My Cookie by chukwuebuka65(m): 10:35pm On Sep 03, 2022 |
jbreezy: Still not working, I guess I will have to store the token in memory on the frontend for the meantime until I can find the solution |
Re: Why Is Heroku Not Setting My Cookie by TastyFriedPussy: 7:47am On Sep 04, 2022 |
chukwuebuka65:next time use python and not nodeJS |
Re: Why Is Heroku Not Setting My Cookie by TastyFriedPussy: 7:47am On Sep 04, 2022 |
chukwuebuka65:next time learn python and not nodeJS |
Re: Why Is Heroku Not Setting My Cookie by arejibadz(m): 8:27am On Sep 04, 2022 |
chukwuebuka65:if I may ask what do you use the token for authentication?? |
Re: Why Is Heroku Not Setting My Cookie by chukwuebuka65(m): 9:31am On Sep 04, 2022 |
arejibadz: I didn’t understand, can you rephrase pls. |
Re: Why Is Heroku Not Setting My Cookie by jbreezy: 11:40am On Sep 04, 2022 |
TastyFriedPussy:Django is more complicated than NodeJs 1 Like |
Re: Why Is Heroku Not Setting My Cookie by Sleekcode: 11:42am On Sep 04, 2022 |
jbreezy:They're 2 different things tho |
Re: Why Is Heroku Not Setting My Cookie by arejibadz(m): 12:04pm On Sep 04, 2022 |
chukwuebuka65:your using token or cookie for authentication you either use session storage or local storage in your frontend to get your tokens from the backend |
Re: Why Is Heroku Not Setting My Cookie by chukwuebuka65(m): 12:18pm On Sep 04, 2022 |
arejibadz: Yea I know I can store the token in local storage but it is not advisable that is why I want to use httponly cookie that javascript cannot access. |
Re: Why Is Heroku Not Setting My Cookie by chukwuebuka65(m): 12:33pm On Sep 04, 2022 |
arejibadz: I finally figured it out. It wasn’t actually heroku problem. It’s from the browser. So it happens that There is a list called “ Mozilla foundation public suffix list” which if the company hosting your app is included in the list, no browser will save any cookie from the website subdomain ( in the case of heroku , *.herokuapp.com). And I am not using a custom domain name. So thats where the problem is coming from. The solution now is to either get a custom domain name or combine my front end and backend together so they can be served by the same server. Thanks for your help sir. 1 Like |
Re: Why Is Heroku Not Setting My Cookie by HassieMalcomson(f): 9:39am On Sep 15, 2022 |
I don't think it is anything related to code. So, don't do anything with code to fix the problem. In this regard, I found a good solution on Stack Overflow, and it is about adding a static route or folder to the Express server. You can also visit this source https://devcenter.heroku.com/articles/cookies-and-herokuapp-com to get all details about Heroku and cookies. However, if Heroku is still creating problems for you, then you should try alternatives with the free tier. Hereof, you can find a variety of Heroku alternatives here https://blog.back4app.com/top-10-heroku-alternatives/ and utilize any of them according to the need of your project. You can simply try Netlify, CapRover, Railway and Google App Engine because they come with free plans. Withal, if you have a reasonable budget, don't skip Open Shift. It provides several appealing advantages. |
Re: Why Is Heroku Not Setting My Cookie by chukwuebuka65(m): 11:36am On Sep 15, 2022 |
HassieMalcomson: Ok. Thanks for the info 2 Likes |
Re: Why Is Heroku Not Setting My Cookie by HassieMalcomson(f): 9:18am On Sep 18, 2022 |
chukwuebuka65: Welcome |
Re: Why Is Heroku Not Setting My Cookie by UncleAyo: 2:52pm On Sep 18, 2022 |
Heroku, has recently changed its terms of free usage. If your application is on free hosting, I think you can now no longer be able to do some of these things for free. Please, check heroku's new term of usage. I may be wrong tho... but that os what I read yesterday. |
Re: Why Is Heroku Not Setting My Cookie by truthCoder: 9:13am On Oct 13, 2022 |
TastyFriedPussy: You evidently have not gotten to the section on cookies and jwt in your tutorials. 1 Like |
(1) (Reply)
Autodesk For Engineers, Architects Etc / Plz Help With Using Pseudo Code For This Algorithm / Hotel Booking Portal
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 45 |