0PricingLogin
Flask Academy · Lesson

Protect Endpoints with jwt_required

Verify the token on each API call.

Guarding a Route

A token is only useful if some routes demand it. The jwt_required decorator turns any view into a members-only endpoint. 🔒

Apply the Decorator

Stack @jwt_required() under your route. Now the view only runs when a valid, unexpired token arrives.

@app.get("/profile")
@jwt_required()
def profile():
    ...

All lessons in this course

  1. Sessions vs Stateless Tokens
  2. Issue Access Tokens on Login
  3. Protect Endpoints with jwt_required
  4. Refresh Tokens and Expiry
← Back to Flask Academy