Flask-login In plotly dash current_user is returning None

Hello All,
I integrate Flask-login in Plotly dash, The current_user from flask-login is working fine inside a callbcak, But i want to populate the sidebar with some links base on the user authenticatication, which is loading in app.layout
The problem now is that when I try to get current_user within the sidebar function, current_user returns None instead of a User object.
I can’t figure out what the problem is; from my understanding, it seems to be the problem of the app loading lifecycle.
any suggestion?

Hello @Arslan,

Yes, you will encounter issues with the initial spin up, as this is done outside of a request.

My recommendation is to have the sidebar be a function that gets called independently based upon the first time the user accesses the home page (after successful login) where it populates their custom locations.

It is actually easier to perform this with a login flow that is outside of dash, in which you send the logged in user to your dash app.


This can be handled via routing the flask app prior to init Dash.

1 Like

Thanks for your reply, i have login flow which is in DASH so i have to find a way to this inside Dash app.

You can still do it all in dash. You’ll need to use the location of the page.

You don’t need to add one, you can use the pages own location. Think it’s _page_location for a trigger. Then return the sidebar to a sidebar div.

1 Like