Добрый день столкнулся с такой проблемой:
При отправке данных login / password на сервер получаю ошибку :
JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
Метод отправки данных на сервер :
let response = await fetch(URL_SERVER_LINK + "/login_client", {
method: "POST",
mode: "no-cors",
credentials: "include",
headers: {
"Access-Control-Allow-Origin": "*",
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
Username: login,
Password: password,
}),
});
Сервер принимает данные вот так:
@application.route('/login_client', methods=['POST'])
def login_client():
auth = request.authorization
username = request.json.get('username', None)
password = request.json.get('password', None)
if not auth or not auth.username or not auth.password:
return make_response('Could not verify', 401, {'WWW-Authenticate' : 'Basic realm="Login required!"'})
client = Client.query.filter_by(name=auth.username).first()
if not client:
return make_response('Could not verify', 401, {'WWW-Authenticate' : 'Basic realm="Login required!"'})
if check_password_hash(client.password, auth.password):
return jsonify({"token": create_access_token(identity=auth.username)})