Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

current_user.is_authenticated returns false in deployment #5

Closed
max454545 opened this issue Jun 4, 2020 · 12 comments
Closed

current_user.is_authenticated returns false in deployment #5

max454545 opened this issue Jun 4, 2020 · 12 comments

Comments

@max454545
Copy link

Hello,

Thanks for making this repository.

I have been using it with success on a localhost, but as soon as I deploy it, on a hosted server, the user authentication stops behaving. As the user logs in, it registers that the user is authenticated, but within less than a 1s the bool current_user.is_authenticated is set to false.

I have tried everything, and this problem is consistent for my code, that includes the code from this repository, and if one puts this repository on a server and runs it.

Thanks and all the best,
Max H

@RafaelMiquelino
Copy link
Owner

RafaelMiquelino commented Jun 4, 2020 via email

@max454545
Copy link
Author

max454545 commented Jun 4, 2020

Hello Rafael,
Thanks for getting back so quickly.

I changed your code by adding the following line to app.py:

app = app.server

I made the above change in order to use the flask internal server. Is this where I am going wrong?

The gif below shows the behavior on a local server (browser on the left), vs the behavior on a hosted server (browser window on the right). In the hosted version, CURRENT USER: TEST disappears because the current_user.is_authenticated is prematurely set to False.

prob_gif

@RafaelMiquelino
Copy link
Owner

I changed your code by adding the following line to app.py:

app = app.server

I made the above change in order to use the flask internal server. Is this where I am going wrong?

You shouldn’t need to do that, just run flask run --host=0.0.0.0 and your app you’ll be served externally. However I recommended you use gunicorn, the Flask internal server is not suitable for production environment. Take a look here for an example on how to serve the app with gunicorn: https://github.com/RafaelMiquelino/flask-text-reader/blob/master/README.md#instructions.

@max454545
Copy link
Author

I have tried gunicorn on a Heroku server (still with the line 'server = app.server') and the problem persisted.

I will try flask run --host=0.0.0.0 and get back to you.

Thank you again

@max454545
Copy link
Author

I am truly stuck.
Our preferred host uses passenger as the application server. The only way that I can think of making the passenger_wsgi.py file is by adding the line 'server = app.server' to app.y, which is the incorrect way to do it.

Do you know how I could make the passenger_wsgi.py file to correctly run
dash-flask-login, without altering app.py?

@max454545
Copy link
Author

I see that dash-auth-flow is also nolonger working in production. Is it possible that Flask login is no longer a viable option for Dash apps?

Here is there app, it exhibits the same faulty behavior as dash-flask-login on my server:
http://dash-auth-flow.herokuapp.com/login

@lapshinmr
Copy link

Hey. Please, take a look at these pages: issue133 and https://dash.plotly.com/urls. It looks like your problem not in the login feature but in the multi-page rendering.

@RafaelMiquelino
Copy link
Owner

@max454545 , I just made some tests and deployed it to Heroku and it behaves like expected, i.e.: I couldn't reproduce your issue. I added the instructions to run it with gunicorn and deploy to Heroku on the README. If you follow this instructions you'll be able to do that too.
I have a working example on the link https://dash-flask-login-rm.herokuapp.com that you can check by yourself. You'll probably need to investigate deeper your code and please share here when you managed to solve it.

@RafaelMiquelino
Copy link
Owner

Actually, I checked it again and it indeed behaves in a strange manner. Maybe there is something to do what @lapshinmr just mentioned.

@RafaelMiquelino
Copy link
Owner

So I forced gunicorn to use only one worker when running on Heroku: https://github.com/RafaelMiquelino/dash-flask-login/blob/master/Procfile#L1.
It is working now but it is more a workaround than a solution. It seems the issue is really related to the mentioned above by @lapshinmr. The Dash maintainer says it is solved from the version 0.11.0 but we are using the version 1.4.1 here and the issue is still there, so it needs to be further investigated.
@max454545, you should probably work on a more robust solution for your case and if you find, please share it here. For the moment I'm closing this issue as this is not related to the login process but to the multi-page rendering process.

@RafaelMiquelino
Copy link
Owner

Another possibility that appears to solve this same issue: #2

@max454545
Copy link
Author

max454545 commented Jun 9, 2020

Thank you @lapshinmr and @RafaelMiquelino for looking into the issue, I appreciate it.

lapshinmr you are completely correct it is not the login feature but in the multi-page rendering.

github.com/russellromney seems to have encountered the same problem and found a solution:
russellromney/dash-auth-flow#2

by using

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants