question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Staying logged in between browser sessions without remember-me

See original GitHub issue

I am not sure what I’m doing wrong, and any pointers in the right direction would be appreciated.

When I log in a user using Flask-login, I check to see if they checked the “remember me” box and then use the appropriate login_user:

if remember:
    login_user(user, remember=True)
else:
    login_user(user)

I don’t know if the remember-me version is working as it’s supposed to, because even when the no-remember login_user(user) is run, the user is remembered. (I thought I might just always be calling the login_user(user, remember=True) code, but the if/else is working correctly.) So, when I log in without clicking the “remember me,” close the browser tab, close the browser, and then come back to the site, I’m still logged in. I thought maybe the cookie wasn’t expiring, but before going to my site I confirmed that the browser doesn’t have it. (Also, no remember-me cookie). If I remove the cookie from my browser either by logging out or through browser settings, I’m logged out and will have to log in if I close and re-open the browser.

For the config, I have SESSION_COOKIE_NAME, REMEMBER_COOKIE_NAME, and REMEMBER_COOKIE_SECURE all set.

Where the user needs to be logged in, I have the @login_required decorator set, or a if current_user.is_authenticated:.

I’ve gone over the docs and my code again and again, and for the life of me I can’t figure out why this is happening.

Ideas?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
maxcountrymancommented, Mar 17, 2016

That’s why the exercise of reducing your problem to the smallest possible set of variables can itself be an answer. 😄

0reactions
kdwarncommented, Mar 17, 2016

Well, if nothing else, posting here and the exercise of minimizing the app made me think of another thing to try because I just couldn’t see how it was the code. It turns out that Chrome’s “Continue where you left off” setting was causing the problem. Once I changed that to “Open the New Tab page,” it worked as expected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

php - "Keep Me Logged In" - the best approach - Stack Overflow
See ircmaxell's answer to this question for a more secure approach. Usually I do something like this: User logs in with 'keep me...
Read more >
What Does the "Keep Me Logged In" Box Do? - MakeUseOf
When you check "Keep me logged in," the site instead sends a cookie that enables a persistent session. This means that the cookie,...
Read more >
What are the differences between “Remember me” and "Stay ...
"Stay Signed In" means just that: the user's session token is preserved with a very long expiration time and won't automatically be cleared...
Read more >
How do I keep logged into websites so I don't have to logging ...
Save this answer. Usually websites will have a "Remember Me" or "Remember Password" option. Make sure that is checked if you want to...
Read more >
stay logged in & remember me - PHP sessions and cookies
"Remember Me" only has an affect on the login page. When a user is attempting to log in, their username is loaded from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found