0

Is there a way to restrict the API endpoint with the @jwt_required decorator looking at only one identity?

Right now, I create the JWT with the identity of an admin user = 1 and standard user = 0. On my route, I have something like this:

@app.route('/add', methods=['POST'])
@jwt_required
def add():
    if request.method == 'POST':
        if get_jwt_identity()[1] == 1:

Is there a cleaner way to check the jwt_identity and perform whatever is defined there for the route? Not sure if my approach is the best.

Thanks!

1 Answer 1

1

You could use a custom decorator to hold that logic: https://flask-jwt-extended.readthedocs.io/en/stable/custom_decorators/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.