[Python] Passing jwt tokken in VUE to api on pyhton and it provide me error 422

Discussão em 'Python' iniciado por Stack, Fevereiro 5, 2025.

  1. Stack

    Stack Membro Participativo

    I try to send access_tokken from VUE template to Python api but it always provide me error 422. What could be problem? To send jwt token in vue I use this:

    const response = await axios.get('http://127.0.0.1:5000/user_info', {
    headers: {
    Authorization: `JWT ${Cookies.get('access_token')}`
    }
    });


    Pyhton api where is send JWT token

    @app.route('/user_info', methods=['GET'])
    @jwt_required()
    def user_info():
    current_user = get_jwt_identity()
    app.logger.info(f"Current user: {current_user}")
    db = connection_pool.get_connection()
    cursor = db.cursor(dictionary=True)

    try:
    cursor.execute("SELECT name, surname, email FROM client_data WHERE id = %s", (current_user['id'],))
    user_info = cursor.fetchone()
    app.logger.info(f"User info: {user_info}") # Log the user info for debugging
    return jsonify(user_info), 200
    except mysql.connector.Error as err:
    app.logger.error(f"Error fetching user info: {err}") # Log the error for debugging
    return jsonify({"error": str(err)}), 500
    finally:
    cursor.close()
    db.close()

    Continue reading...

Compartilhe esta Página