Fix: handle stale sessions and migrated users without household_id

This commit is contained in:
agentbox
2026-07-31 22:02:06 +00:00
parent a318b577cb
commit 1e57a886f4
2 changed files with 10 additions and 4 deletions
+7 -2
View File
@@ -18,12 +18,13 @@ meals_bp = Blueprint("meals", __name__)
def login_required(f):
"""Decorator: redirect to login if not authenticated."""
"""Decorator: redirect to login if not authenticated or session is stale."""
from functools import wraps
@wraps(f)
def wrapper(*args, **kwargs):
if "user_id" not in session:
if "user_id" not in session or "household_id" not in session:
session.clear()
return redirect(url_for("auth.login"))
return f(*args, **kwargs)
@@ -51,6 +52,10 @@ def dashboard():
except ValueError:
flash("Invalid date format. Use YYYY-MM-DD.", "error")
if household_id is None:
session.clear()
return redirect(url_for("auth.login"))
data = get_dashboard_data(today, household_id)
return render_template(
"dashboard.html",