diff --git a/app/ayanova/src/api/apiutil.js b/app/ayanova/src/api/apiutil.js new file mode 100644 index 00000000..fc2d53b9 --- /dev/null +++ b/app/ayanova/src/api/apiutil.js @@ -0,0 +1,12 @@ +export default { + status(response) { + if (response.status >= 200 && response.status < 300) { + return Promise.resolve(response); + } else { + return Promise.reject(new Error(response.statusText)); + } + }, + json(response) { + return response.json(); + } +}; diff --git a/app/ayanova/src/api/auth.js b/app/ayanova/src/api/auth.js index cde77a8f..2ef5ccc5 100644 --- a/app/ayanova/src/api/auth.js +++ b/app/ayanova/src/api/auth.js @@ -1,22 +1,22 @@ /*eslint-disable*/ -import ayconfig from "../utils/config"; +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 status(response) { +// if (response.status >= 200 && response.status < 300) { +// return Promise.resolve(response); +// } else { +// return Promise.reject(new Error(response.statusText)); +// } +// } -function json(response) { - var v = response.json(); - return v; -} +// function json(response) { +// return response.json(); +// } export default { async authenticate(login, password) { - return fetch(ayconfig.apiUrl + "auth", { + return fetch(config.apiUrl + "auth", { method: "post", mode: "cors", headers: { @@ -28,18 +28,12 @@ export default { password: password }) }) - .then(status) - .then(json) + .then(api.status) + .then(api.json) .then(function(data) { - // console.log( - // "AUTH.JS::authenticatepromise() -> Request succeeded with JSON response", - // data - // ); return data; }) .catch(function(error) { - // console.log("AUTH.JS::authenticatepromise() -> Request failed", error); - //return error; return Promise.reject(error); }); } diff --git a/devdocs/todo.txt b/devdocs/todo.txt index eba8e16c..6b868cb9 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -43,6 +43,7 @@ NEXT: Test authorization code to login even if just doing it from code for now t - Stage 2: - Make it work with the backend: - Login, logout + - Error handling at client (log? display?) - Notification of some kind (bell / toast) - Localized text - About page with license info