Flask Session does not hold any value between Requests Flask Session does not hold any value between Requests flask flask

Flask Session does not hold any value between Requests


As from our discussions in comments, we came to know that sessions don't persist between the API calls, if both frontend and backend are hosted in different ports.

Now sending cookies from Flask to React frontend also cannot be achieved, because of the same reason. It only works for Flask frontends.

You can do one thing, what ever you want to set as cookies, that you can send it in response from Flask, and from React you can set those cookies. You'l have to send this value to Flask for every request. I am not familiar with React, but I did like below in my Angular app (this is the very basic way):

document.cookie = 'token='+result.token

In angular you can do this easily with third party library also, the following like will help you : https://itnext.io/angular-8-how-to-use-cookies-14ab3f2e93fc

And in React, this link will help you : https://stackoverflow.com/a/43684059/6635464


You are sending cross-origin requests, which by default do not allow cookies. Try to initialize Flask-CORS as follows:

CORS(app, supports_credentials=True)

More information: https://flask-cors.readthedocs.io/en/latest/api.html#using-cors-with-cookies.


I'm also using React with Next.JS as frontend and Flask as backend.

The issue is most likely due to CORS request, since your React frontend and Flask backend are not on the same port.

And using Flask-CORS is the way to go, the same confirmed as @Miguel

e.g. CORS(app, supports_credentials=True)

I'm using a fetch to send request in React, so including credentials: "include" will do the job