I’m experimenting with dash-flask-login (https://github.com/RafaelMiquelino/dash-flask-login) 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:
@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')])
if pathname == ‘/’:
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?