Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session is shared between two Flask apps on localhost

So, I have two Flask apps running on localhost, one on the port 5001, and the other one on the port 5003, and apparently both are using the same session. If I log in on one app, it logs out on the other. And for example, recently, if I logged in using my email on one app, it would also log in my account on the other app, since I have users using that email on both apps, and I was using the email as an user identifier, but that stop happening when I used another id for the users.

I'm using Flask-Login, and Google Chrome (the same thing happens in Edge).

I'm not really sure if this could also happen in production, we'll probably use the same host for both apps, so that would be a problem. If this is something related only to localhost, then it's ok, but I don't think that's the case.

Any idea of what could be happening here?

Thanks in advance.

like image 509
Daniel Avatar asked Feb 17 '17 14:02

Daniel


1 Answers

I had a similar problem, and I think the cause is that both instances would use the same "session cookie" in the browser.

The solution that fixed it for me was renaming the SESSION_COOKIE_NAME which is session by default.

app.config.update(SESSION_COOKIE_NAME=<new_session_name>)

I found the solution via: https://stackoverflow.com/a/45497948/380038

like image 63
Framester Avatar answered Oct 04 '22 20:10

Framester