This commit is contained in:
@@ -1,40 +1,37 @@
|
||||
/*eslint-disable*/
|
||||
import config from "../utils/config";
|
||||
import api from "./apiutil";
|
||||
|
||||
// function status(response) {
|
||||
// if (response.status >= 200 && response.status < 300) {
|
||||
// return Promise.resolve(response);
|
||||
// } else {
|
||||
// return Promise.reject(new Error(response.statusText));
|
||||
// }
|
||||
// }
|
||||
|
||||
// function json(response) {
|
||||
// return response.json();
|
||||
// }
|
||||
import { processLogin, processLogout } from "../utils/auth";
|
||||
|
||||
export default {
|
||||
async authenticate(login, password) {
|
||||
return fetch(config.apiUrl + "auth", {
|
||||
method: "post",
|
||||
mode: "cors",
|
||||
headers: {
|
||||
Accept: "application/json, text/plain, */*",
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
login: login,
|
||||
password: password
|
||||
return (
|
||||
fetch(config.apiUrl + "auth", {
|
||||
method: "post",
|
||||
mode: "cors",
|
||||
headers: {
|
||||
Accept: "application/json, text/plain, */*",
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
login: login,
|
||||
password: password
|
||||
})
|
||||
})
|
||||
})
|
||||
.then(api.status)
|
||||
.then(api.json)
|
||||
.then(function(data) {
|
||||
return data;
|
||||
})
|
||||
.catch(function(error) {
|
||||
return Promise.reject(error);
|
||||
});
|
||||
.then(api.status)
|
||||
.then(api.json)
|
||||
.then(processLogin)
|
||||
.then(() => {
|
||||
return Promise.resolve(true);
|
||||
}) //succeeded, nothing to return
|
||||
// .then(function(data) {
|
||||
// //todo: this should just return a bool on successful login and let the util\auth handle storing token etc
|
||||
// //router will handle views available based on roles etc so login only really needs to know if it succeeded or not.
|
||||
// return data;
|
||||
// })
|
||||
.catch(function(error) {
|
||||
processLogout();
|
||||
return Promise.reject(error);
|
||||
})
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user