Problems with trying to implement flask-login into my multi-page app

nexus_callback is the equivalent of ‘page-1’ in my original example.

‘nexus_callback’ is calling the ‘layout function’ from nexus_layout.

current_user was originally in ‘nexus_layout’.

I also tried moving it into ‘nexus_callback’, but the error remained.

from . import nexus_layout as page_layout
from flask_login import current_user
from dash import dcc, html
if not current_user.is_authenticated:
    layout = html.Div([dcc.Link("login", href="/login"), " to continue"])
else:
    layout = page_layout.layout()

My guess that it is trying to run this at startup, which means it is undefined at initialization.

Try to wrap it so that it only gets called when a user is interacting.

I don’t know how to approach doing that…

Try this:

from . import nexus_layout as page_layout
from flask_login import current_user
from dash import dcc, html
layout = html.Div([dcc.Link("login", href="/login"), " to continue"])
if current_user:
    if current_user.is_authenicated:
         layout = page_layout.layout()
1 Like