# src/decorators.py from functools import wraps from flask import session, flash, redirect, url_for, request def login_required(f): """Decorator to ensure user is logged in before accessing a route.""" @wraps(f) def decorated_function(*args, **kwargs): if 'user_id' not in session: flash('Please log in to access this page.', 'warning') # Store the intended destination to redirect after login return redirect(url_for('auth.login', next=request.url)) return f(*args, **kwargs) return decorated_function