except (jwt.InvalidTokenError, KeyError): return make_response(jsonify({"message": "EXAM/auth: Invalid token!"}), 401) ... def teacher_required(func): """ checks if the authenticated user is a teacher :param func: callback function :return: the decorated function """ @wraps(func) def wrap(*args, **kwargs): if g.user.role != 'teacher': return make_response(jsonify({"message": "not allowed for students"}), 403) return func(*args, **kwargs) return wrap