from functools import wraps  # Import wraps
from flask import session, redirect, url_for

def login_required(f):
    @wraps(f)  # Preserve the original function's metadata
    def decorated_function(*args, **kwargs):
        if 'username' not in session:
            return redirect(url_for('homepage.login'))
        return f(*args, **kwargs)
    return decorated_function