add error handling to the auth page
This commit is contained in:
parent
ba84e606c5
commit
0d0f934a9a
|
@ -1,23 +1,32 @@
|
|||
<template>
|
||||
<base-card>
|
||||
<form @submit.prevent="submitForm">
|
||||
<div class="form-control">
|
||||
<label for="email">E-Mail</label>
|
||||
<input type="email" id="email" v-model.trim="email" />
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" v-model.trim="password" />
|
||||
</div>
|
||||
<p v-if="!formIsValid">
|
||||
Please enter a valid email and password (min. 6 characters).
|
||||
</p>
|
||||
<base-button>{{ submitButtonCaption }}</base-button>
|
||||
<base-button type="button" mode="flat" @click="switchAuthMode">{{
|
||||
switchModeButtonCaption
|
||||
}}</base-button>
|
||||
</form>
|
||||
</base-card>
|
||||
<div>
|
||||
<base-dialog :show="!!error" title="An error occured" @close="handleError">
|
||||
<p>{{ error }}</p>
|
||||
</base-dialog>
|
||||
<base-dialog :show="isLoading" title="Authenticating..." fixed>
|
||||
<base-spinner></base-spinner>
|
||||
</base-dialog>
|
||||
|
||||
<base-card>
|
||||
<form @submit.prevent="submitForm">
|
||||
<div class="form-control">
|
||||
<label for="email">E-Mail</label>
|
||||
<input type="email" id="email" v-model.trim="email" />
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" v-model.trim="password" />
|
||||
</div>
|
||||
<p v-if="!formIsValid">
|
||||
Please enter a valid email and password (min. 6 characters).
|
||||
</p>
|
||||
<base-button>{{ submitButtonCaption }}</base-button>
|
||||
<base-button type="button" mode="flat" @click="switchAuthMode">{{
|
||||
switchModeButtonCaption
|
||||
}}</base-button>
|
||||
</form>
|
||||
</base-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
@ -27,7 +36,9 @@ export default {
|
|||
email: '',
|
||||
password: '',
|
||||
formIsValid: true,
|
||||
mode: 'login'
|
||||
mode: 'login',
|
||||
isLoading: false,
|
||||
error: null
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
|
@ -47,7 +58,7 @@ export default {
|
|||
}
|
||||
},
|
||||
methods: {
|
||||
submitForm() {
|
||||
async submitForm() {
|
||||
this.formIsValid = true;
|
||||
if (
|
||||
this.email === '' ||
|
||||
|
@ -57,22 +68,32 @@ export default {
|
|||
this.formIsValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.mode === 'login') {
|
||||
//
|
||||
} else {
|
||||
this.$store.dispatch('signup', {
|
||||
email: this.email,
|
||||
password: this.password
|
||||
});
|
||||
this.isLoading = true;
|
||||
try {
|
||||
if (this.mode === 'login') {
|
||||
//
|
||||
} else {
|
||||
await this.$store.dispatch('signup', {
|
||||
email: this.email,
|
||||
password: this.password
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
this.error = error;
|
||||
}
|
||||
this.isLoading = false;
|
||||
},
|
||||
|
||||
switchAuthMode() {
|
||||
if (this.mode === 'login') {
|
||||
this.mode = 'signup';
|
||||
} else {
|
||||
this.mode = 'login';
|
||||
}
|
||||
},
|
||||
|
||||
handleError() {
|
||||
this.error = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Reference in New Issue