Saturday, 19 September 2020

How to set httpOnly cookie (the jwt for auth) if my backend and frontend are on different domain

I'm using jwt for authentication.My backend is Node.js, Express and fronted is Nextjs. For some reason, I need to keep my backend and frontend totally separate in this project.My backend is running on localhost:5000and my frontend running on localhost:3000I don't want to save my jwt in localStorage or in a non httpOnly cookie. But I cannot set a httpOnly cookie from my server now because of the same-origin policy.And I don't think there is a way for me to set a httpOnly cookie from Nextjs right?Now is it totally undoable? Is there any way for me to handle this situation better? Or storing the jwt in localStorage is my only option!Thanks guys!

Submitted September 19, 2020 at 08:46AM by shamimbhai

No comments:

Post a Comment