Hello I have created login system for dash app exactly as it is in the example with external package dash-flask-login
but I have a problem that it just do not log in. The problem looks basically like this: I am entering login data and passwort, hitting submit and after this current_user.is_authenticated
returns True
but the page redirects(refreshes) and then it returns False
. It seems like it just forget User data while it redirects. When I run my app on edge everythingn works as intended. There are my callbacks:
@login_app.callback(
Output('h1', 'n_clicks'),
[Input('submit-button', 'n_clicks')],
[State('uname-box', 'value'),
State('pwd-box', 'value')]
)
def login(n_clicks, uname, pwd):
print(current_user.is_authenticated)
if uname:
user = User.query.filter_by(username = uname).first()
if user is None or not user.check_password(pwd):
print('error')
login_user(user)
print(current_user)
print(user.is_authenticated)
return True
else:
pass
@server.route('/login/', methods=['GET', 'POST'])
def login():
if current_user.is_authenticated and request.method == 'POST':
if request.args.get('next'):
return redirect(request.args.get('next'))
else:
return redirect('/login/')
else:
return redirect('/')
@login_manager.user_loader
def load_user(id):
return User.query.filter_by(id=id).first()
While logging in firefox console reports this error:
Unhandled promise rejection TypeError: "NetworkError when attempting to fetch resource." [dash_renderer.min.js:12:23109](https://unpkg.com/dash-renderer@0.14.3/dash_renderer/dash_renderer.min.js)
How to handle this problem? The problem started when I have implemented User model with database. When I was using this example snippet with ‘fake users’ it worked aswell:
@login_app.callback(
Output('h1', 'n_clicks'),
[Input('submit-button', 'n_clicks')],
[State('uname-box', 'value'),
State('pwd-box', 'value')]
)
def login(n_clicks, uname, pwd):
if uname == 'user' and pwd == 'password':
login_user(load_user(users[0].name))
else:pass