Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve error message for log in #936

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions src/components/Cards/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
<v-toolbar-title>{{title}}</v-toolbar-title>
</v-toolbar>
<v-card-text>
<v-alert
v-if="errorMessage"
outlined
color="error"
type="error"
dense
border="left"
:icon=false
>
{{ errorMessage }}
</v-alert>
<v-text-field
id="inputEmail"
prepend-icon="mdi-email"
Expand All @@ -13,8 +24,6 @@
type="email"
required
v-model="email"
:disabled="loggingIn"
:error-messages="error['email']"
/>
<v-text-field
id="inputPassword"
Expand All @@ -24,8 +33,7 @@
type="password"
required
v-model="password"
:disabled="loggingIn"
:error-messages="error['password']"
ref="passwordField"
/>
<router-link to="/forgotten-password" style="text-decoration: none">Forgot your password?</router-link>
</v-card-text>
Expand All @@ -48,7 +56,7 @@ export default {
return {
email: '',
password: '',
error: [],
errorMessage: '',
loggingIn: false
}
},
Expand All @@ -68,29 +76,24 @@ export default {
},
login (evt) {
evt.preventDefault()

this.loggingIn = true
const email = this.email
const password = this.password
this.error = []
this.errorMessage = ''

this.$store
.dispatch('login', { email, password })
.then(() => this.$router.push('/dashboard'))
.catch(err => {
console.log(err.response)

// If the api gave use details of the error, then use them
if (err.response && err.response.data && err.response.data.errors) {
if (err.response.data.errors.email) {
this.error.email = err.response.data.errors.email[0]
}
if (err.response.data.errors.password) {
this.error.password = err.response.data.errors.password[0]
}
} else {
this.error.email = 'Could not log in.'
this.error.password = 'Could not log in.'
}
this.errorMessage = 'Incorrect username or password. Please try again.'

this.password = ''

this.$nextTick(() => {
this.$refs.passwordField.$el.querySelector('input').focus()
})

this.loggingIn = false
})
Expand All @@ -102,7 +105,6 @@ export default {
<style lang="css" scoped>
.card-width {
width: 477px;

}

@media (max-width: 620px) {
Expand Down
Loading