If configs apiUrl not defined fallback to origin.
Also removed dependency of login and register to redirect response from server. Now we send json data with status = 200 when successfully login/registered. Username input element also is set to not capitalize input.
This commit is contained in:
10
src/api.js
10
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
|
||||
} 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
|
||||
} else {
|
||||
return handleErrors(resp)
|
||||
}
|
||||
|
||||
@@ -4,16 +4,20 @@
|
||||
<form aria-label="User registration" @submit.prevent>
|
||||
<div class="label-div">
|
||||
<label>Brukernavn</label>
|
||||
<input type="text" v-model="username" placeholder="Brukernavn" @keyup.enter="login" />
|
||||
<input type="text"
|
||||
v-model="username"
|
||||
placeholder="Brukernavn"
|
||||
autocapitalize="none"
|
||||
@keyup.enter="submit" />
|
||||
</div>
|
||||
<div class="label-div row">
|
||||
<label>Passord</label>
|
||||
<input type="password" v-model="password" placeholder="Passord" @keyup.enter="login" />
|
||||
<input type="password" v-model="password" placeholder="Passord" @keyup.enter="submit" />
|
||||
</div>
|
||||
|
||||
<button class="vin-button" @click="register">Registrer bruker</button>
|
||||
<button class="vin-button" @click="submit">Registrer bruker</button>
|
||||
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
<div v-if="error" class="error">{{ error }}</div>
|
||||
</form>
|
||||
</div>
|
||||
</template>
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,14 +4,18 @@
|
||||
<form aria-label="User signin" @submit.prevent>
|
||||
<div class="label-div">
|
||||
<label>Brukernavn</label>
|
||||
<input type="text" v-model="username" placeholder="Brukernavn" @keyup.enter="login" />
|
||||
<input type="text"
|
||||
v-model="username"
|
||||
placeholder="Brukernavn"
|
||||
autocapitalize="none"
|
||||
@keyup.enter="submit" />
|
||||
</div>
|
||||
<div class="label-div row">
|
||||
<label>Passord</label>
|
||||
<input type="password" v-model="password" placeholder="Passord" @keyup.enter="login" />
|
||||
<input type="password" v-model="password" placeholder="Passord" @keyup.enter="submit" />
|
||||
</div>
|
||||
|
||||
<button class="vin-button" @click="login">Logg inn</button>
|
||||
<button class="vin-button" @click="submit">Logg inn</button>
|
||||
|
||||
<div v-if="error" class="error">{{ error }}</div>
|
||||
</form>
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user