from functools import wraps from typing import Callable from flask import abort, jsonify, make_response, request from src.utils import is_authenticated def login_required(handler: Callable) -> Callable: """Authentication performed by checking user's token. Use for api's where it is required. Args: handler: handler function to wrap Returns: wrapped handler Raises: Unauthorized: 401 if user's os expired. """ @wraps(handler) def wrapper(*args, **kwargs): if not is_authenticated(): abort(make_response(jsonify(message="Token has expired"), 401)) return handler(request, **dict(request.args)) return wrapper