diff --git a/src/api.js b/src/api.js index a79cfca..6a7824d 100644 --- a/src/api.js +++ b/src/api.js @@ -1,4 +1,4 @@ -const BASE_URL = __APIURL__ || "http://localhost:30030/"; +const BASE_URL = __APIURL__ || window.location.origin; const statistics = () => { const url = new URL('/api/purchase/statistics', BASE_URL) @@ -119,17 +119,13 @@ const login = (username, password) => { "Content-Type": "application/json" }, method: "POST", - redirect: "follow", body: JSON.stringify({ username, password }) } return fetch(url.href, options) .then(resp => { if (resp.ok) { - if (resp.bodyUsed) - return resp.json() - else - return resp + return resp.json() } else { return handleErrors(resp) } @@ -143,17 +139,13 @@ const register = (username, password) => { "Content-Type": "application/json" }, method: "POST", - redirect: 'follow', body: JSON.stringify({ username, password }) } return fetch(url.href, options) .then(resp => { if (resp.ok) { - if (resp.bodyUsed) - return resp.json() - else - return resp + return resp.json() } else { return handleErrors(resp) } diff --git a/src/components/CreatePage.vue b/src/components/CreatePage.vue index d8cf2e8..0afaf2b 100644 --- a/src/components/CreatePage.vue +++ b/src/components/CreatePage.vue @@ -4,16 +4,20 @@
- +
- +
- + -

{{ error }}

+
{{ error }}
@@ -29,17 +33,10 @@ export default { } }, methods: { - register() { + submit() { register(this.username, this.password) - .then(resp => { - if (resp.redirected) { this.$router.push("/") } - }) - .catch(this.registerErrorResponse) - - }, - registerErrorResponse(error) { - console.log("error", error) - this.error = error.message || error + .then(resp => this.$router.push("/")) + .catch(error => this.error = error.message || error) } } }; diff --git a/src/components/LoginPage.vue b/src/components/LoginPage.vue index fdf94b6..a5f950c 100644 --- a/src/components/LoginPage.vue +++ b/src/components/LoginPage.vue @@ -4,14 +4,18 @@
- +
- +
- +
{{ error }}
@@ -29,16 +33,10 @@ export default { } }, methods: { - login() { + submit() { login(this.username, this.password) - .then(resp => { - if (resp.redirected) { this.$router.push("update") } - }) - .catch(this.loginErrorResponse) - - }, - loginErrorResponse(error) { - this.error = error.message || error + .then(resp => this.$router.push("update")) + .catch(error => this.error = error.message || error) } } };