Home > OS >  Why doesn't Flask see JWT cookie while sending POST request
Why doesn't Flask see JWT cookie while sending POST request

Time:03-22

I am trying to submit simple HTML form to my Flask app on this POST route but I am getting unauthorized error, because Flask/JWT (I am not sure) doesn't find it in cookies. It works fine with the GET request on the same route (it finds the access_token in cookies). What is the problem with cookies in POST request? Thank you!

@app.route('/someRoute', methods=["GET", "POST"])
@jwt_required(locations=["cookies"])
def someRoute():
    if request.method == "GET":
        return render_template("page.html") **works fine**
    elif request.method == "POST":
        **there is the problem**

CodePudding user response:

How do you send your POST request? You need to implicit set withCredentials if you are sending the request from the browser

For example:

axios.get(url, { withCredentials: true });

CodePudding user response:

What is the actual error that you are seeing? I suspect you aren’t sending the CSRF double submit token in the request, which is required for POST requests. See the docs here: https://flask-jwt-extended.readthedocs.io/en/stable/token_locations/#cookies

  • Related