i am using flask sessions for a simple login system. There are 3 routes in question.
def home() def checkLogin() def read()
you start at home(), attempt a login, begin a session if successful, return home() but with the session modifying the page contents, and then you can go to read().
the login part works as expected (and until recently the entire thing was fine). However, when i go to read() and check again for a session, it returns "None" as though the session has vanished. this only happens in chrome/safari/firefox. not edge or opera
it seems to be related to me using a domain name, since my locally hosted version works as intended on any browser. using the pythonanywhere URL also works as intended. It's only when I browse via domain name that it breaks down.
I'm confused as to why the session works fine for the first two functions but then disappears when i move to the third?
anyone have any ideas?? Below is the simplified code for reference
@app.route("/home") def home(): if session.get('logged-in'): # do some fluff stuff return render_template('index.html', someVars) return render_template('login.html') # the start point is login.html @app.route("/home", methods=['POST']) def checkLogin(): if session.get('logged-in'): return home() # already logged in, go show index.html. THIS WORKS AS EXPECTED # grab login credentials from the submitted form form # hash pword and check against db if <pass the pword check>: session['logged-in'] = True session.permanent = True app.permanent_session_lifetime = timedelta(days=1) else: sesssion['logged-in'] = False return home() # call home again and go to index.html/login.html as appropriate @some routes def read(some vars): if not session.get('logged-in'): # when it goes wrong, session.get('logged-in') returns None, rather than True or False if not sesssion.get('free'): # a bool that gives a free taster without user login. this should logically always be true as of how my code is now, but currently returns None return home() # THIS IS WHERE IT IS INCORRECTLY RETURNING HOME AS THOUGH THE SESSION DOES NOT EXIST - BUT ONLY IN CHROME/SAFARI/FIREFOX else: # get the user's ID number for later if they are logged in # blah blah lots more stuff