Hi there
I’m experimenting with dash-flask-login (GitHub - RafaelMiquelino/dash-flask-login: Implementation of Flask-login on top of Dash.) and making some changes to it. The GitHub code has a a login page at ‘/’ and a ‘success’ page at ‘/success’, for when a valid login is entered.
I want to change this so that the login page is still at ‘/’, but when a valid login is entered, the success page is loaded at ‘/’.
How I’ve tried to achieve this is as follows:
login.py:
@app.callback(Output('urlLogin', 'pathname'), [Input('loginButton', 'n_clicks')], [State('usernameBox', 'value'), State('passwordBox', 'value')]) def sucess(n_clicks, username, password): user = User.query.filter_by(username=username).first() if user: if check_password_hash(user.password, password): login_user(user) return '/' else: pass else: pass
I have changed return ‘/success’ to return ‘/’ i.e. stay on same page
In index.py, I’m handling page URL routing like so:
@app.callback(Output('pageContent', 'children'), [Input('url', 'pathname')])
def displayPage(pathname):
if pathname == ‘/’:
if current_user.is_authenticated:
return home.layout
else:
return login.layout
Where home.layout is my ‘success’ layout.
However, this isn’t working as expected. When a valid login is entered, the page just doesn’t change/refresh and it just stays like this:
But if I refresh the page manually, I then see home.layout as I am now logged in.
Is my callback in login.py correct? It’s like I need to trigger a page refresh rather than returning ‘/’ (which the Url is at anyway) - is that possible?