Forums

Flask-Login : login_user(user) not working

Hi, I am trying to implement a user feature on my web app that requires users to login, however, after verifying the user/password and setting login_user(user), when the page redirects to home, it’s not remembering the user. I have narrowed it down to the area where I state login_user(user) and wonder if there is a known issue. I am also open to hearing other theories that I can investigate. Many Thanks James

It's hard to tell without looking at your code -- do you have a user_loader callback as per the docs?

Yes I believe I have. I have been unable to copy and paste the code from my browser but managed to create a share link. https://www.pythonanywhere.com/user/Jimmeywho/shares/a1e4734a20234b69bf1bf8e92f30557e/

So now login is returning None (as print call returns nothing). Did you have this issue with commented redirect as well?

Yes, I was noticing it where I was redirecting back to home and it wasn’t remembering the user and not providing a view unique to logged in user.

So I understand that you have it all sorted now.

No not yet. Still getting the same error

I can confirm that I have been able to resolve the issue. The script was unable to connect to the database which turned out to be because it was unable to see the information within an environment file. I have amended the script to now identify the location of the environment file rather than expecting it to be in the cwd. Thank you all for your help!

Glad to hear that!