plotly / dash-labs

Work-in-progress technical previews of potential future Dash features.
MIT License
139 stars 39 forks source link

Flask authentication with multipage app #90

Closed bsauvage1 closed 2 years ago

bsauvage1 commented 2 years ago

I have tried unsuccessfully to combine dash multipage with flask authentication as described here: https://github.com/RafaelMiquelino/dash-flask-login

I tried two different approaches: 1/ embed dl.plugins.page_container inside the display_page callback, but it doesn't update post identification: @app.callback(Output('page-content', 'children'), [Input('url', 'pathname'), ]) def display_page(pathname): if pathname == '/': return login.layout elif pathname == '/login': return login.layout elif pathname == '/logout': if current_user.is_authenticated: logout_user() return logout.layout else: return logout.layout else: if current_user.is_authenticated: return dl.plugins.page_container else: return login_fd.layout

2/ try to add the identification loop inside the individual pages, by conditionning the page layout: if current_user != None: rootLayout_home = rootLayout_home if current_user.is_authenticated else html.Div() else: rootLayout_home = html.Div()

But this doesn't work either - no warning or error just doesn't take auth into account.

My apologies I am not a good programmer and hard for me to recreate an mwe. Please let me know if you have some idea or if this isn't the right place to post this.

AnnMarieW commented 2 years ago

@bsauvage1 Please see the example of integrating flask-login with dash-labs here: https://github.com/AnnMarieW/dash-flask-login

Also, for more information, check out this Dash Community Forum post which includes a link to a medium article which you may find helpful.

bsauvage1 commented 2 years ago

@AnnMarieW this is AWESOME! Thank you very much for this, this is exactly what I was looking for! Very excited by this! Many thanks and keep up the amazing job on Dash!