Session expires while switching to another app.route in flask

Session expires when the '/mobile-confirmation' app.route runs and the user redirects to login page

@app.route("/signup", methods=["GET", "POST"])
def signup():
    if request.method == "POST":
        #SignUp form Insert codes

        db.execute("SELECT tempcode FROM users WHERE id = %s", [userID])
        tmpcode = db.fetchall()
        sms_soap.send_by_base_number([tmpcode[0][0]], phonenum[0][0], 999999)

        executor.submit(tempcodecountdown, username)
        session["user_id"] = userID

        return redirect("/mobile-confirmation")
        return render_template("signup.html")

@app.route("/mobile-confirmation", methods=["GET", "POST"])
def confirmmobile():
    user_id = session["user_id"]
    if request.method == "POST":
        enteredcode = request.form.get("tempcode")
        db.execute("SELECT tempcode FROM users WHERE id = %s", [user_id])
        tmpcode = db.fetchall()
        if enteredcode == tmpcode[0][0]:
            db.execute("UPDATE users SET activation = %s WHERE id = %s", ['yes', user_id])
        return redirect('/dashboard')
        return render_template("mobileconfirmation.html")

and these are session settings

def after_request(response):
    response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
    response.headers["Expires"] = 0
    response.headers["Pragma"] = "no-cache"
    return response

app.config["SESSION_FILE_DIR"] = mkdtemp()
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"

app.config["TEMPLATES_AUTO_RELOAD"] = True
app.config['SESSION_COOKIE_SAMESITE'] = "None"
app.config['SESSION_COOKIE_SECURE'] = True

it was working correctly in another ide but now I have this problem on cpanel

Back to Top