Добрый вечер.Есть такой запрос
import decode from 'jwt-decode';
export default class AuthService {
constructor(domain) {
this.fetch = this.fetch.bind(this)
this.login = this.login.bind(this)
this.getProfile = this.getProfile.bind(this)
}
login(username, password) {
// Get a token
return this.fetch('http://id.cryptofiles.org:2212/api/users/login/', {
method: 'POST',
mode:'no-cors',
headers: {
"Accept": "application/json; odata=nometadata",
"Content-Type": "application/json;odata=nometadata",
},
'Content-Type': 'application/json',
body: JSON.stringify({
username,
password
})
}).then(res => {
this.setToken(res.auth_token)
return Promise.resolve(res);
})
}
loggedIn() {
// Checks if there is a saved token and it's still valid
const token = this.getToken()
return !!token && !this.isTokenExpired(token) // handwaiving here
}
isTokenExpired(token) {
try {
const decoded = decode(token);
if (decoded.exp < Date.now() / 1000) {
return true;
}
else
return false;
}
catch (err) {
return false;
}
}
setToken(idToken) {
// Saves user token to localStorage
localStorage.setItem('auth_token', idToken)
}
getToken() {
// Retrieves the user token from localStorage
return localStorage.getItem('auth_token')
}
logout() {
// Clear user token and profile data from localStorage
localStorage.removeItem('auth_token');
}
getProfile() {
return decode(this.getToken());
}
fetch(url, options) {
// performs api calls sending the required authentication headers
const headers = {
"Accept": "application/json; odata=nometadata",
"Content-Type": "application/json;odata=nometadata",
}
if (this.loggedIn()) {
headers['Authorization'] = 'Bearer ' + this.getToken()
}
return fetch(url, {
headers,
...options
})
.then(this._checkStatus)
.then(response => response.json())
}
_checkStatus(response) {
// raises an error in case response status is not a success
if (response.status >= 200 && response.status < 300) {
return response
} else {
var error = new Error(response.statusText)
error.response = response
throw error
}
}
}
но сервер отправляет 415 ошибку, в чем может быть проблема?