Home > database >  JWT cookies on back-end vs front-end
JWT cookies on back-end vs front-end

Time:03-02

I have a back-end (express api ) on abcd.com domain and a front-end (nextjs) on efg.com I know that setting up JWT (cookie) on my express back-end and using it on another domain for the front-end is impossible . But I have some questions :

  1. Is setting up JWT on back-end localstorage ( instead of cookie ) is a good aproach and creating JWT on abcd.com localstorage ( back-end ) while my fron-end is on efg.com is OK and I will be able to read it later from front-end ?
  2. Shoould I forget about setting up JWT on my back-end and go with Nextjs authentication instead ?

CodePudding user response:

First of all I don't think that use back-end local storage is a good idea. Because, don't forget that if multiple user needs to connect from any point, you will need to store each local value for each user.

While using cookies allow you to store it from each request "automatically".

Why setting up Cookie from your express back-end is impossible ? Do you have any error while trying to do it ?

I suppose at this point that it is a CORS issue. You need to take a look at CORS option in your server-side.

Here is, i think an answers that could help. https://stackoverflow.com/a/46412839/17913593

Hope i could help you a little bit.

  • Related