55 <v-toolbar-title >{{title}}</v-toolbar-title >
66 </v-toolbar >
77 <v-card-text >
8+ <v-alert
9+ v-if =" errorMessage"
10+ outlined
11+ color =" error"
12+ type =" error"
13+ dense
14+ border =" left"
15+ :icon =false
16+ >
17+ {{ errorMessage }}
18+ </v-alert >
819 <v-text-field
920 id =" inputEmail"
1021 prepend-icon =" mdi-email"
1324 type =" email"
1425 required
1526 v-model =" email"
16- :disabled =" loggingIn"
17- :error-messages =" error['email']"
1827 />
1928 <v-text-field
2029 id =" inputPassword"
2433 type =" password"
2534 required
2635 v-model =" password"
27- :disabled =" loggingIn"
28- :error-messages =" error['password']"
36+ ref =" passwordField"
2937 />
3038 <router-link to =" /forgotten-password" style =" text-decoration : none " >Forgot your password?</router-link >
3139 </v-card-text >
@@ -48,7 +56,7 @@ export default {
4856 return {
4957 email: ' ' ,
5058 password: ' ' ,
51- error : [] ,
59+ errorMessage : ' ' ,
5260 loggingIn: false
5361 }
5462 },
@@ -68,29 +76,24 @@ export default {
6876 },
6977 login (evt ) {
7078 evt .preventDefault ()
71-
7279 this .loggingIn = true
7380 const email = this .email
7481 const password = this .password
75- this .error = []
82+ this .errorMessage = ' '
83+
7684 this .$store
7785 .dispatch (' login' , { email, password })
7886 .then (() => this .$router .push (' /dashboard' ))
7987 .catch (err => {
8088 console .log (err .response )
8189
82- // If the api gave use details of the error, then use them
83- if (err .response && err .response .data && err .response .data .errors ) {
84- if (err .response .data .errors .email ) {
85- this .error .email = err .response .data .errors .email [0 ]
86- }
87- if (err .response .data .errors .password ) {
88- this .error .password = err .response .data .errors .password [0 ]
89- }
90- } else {
91- this .error .email = ' Could not log in.'
92- this .error .password = ' Could not log in.'
93- }
90+ this .errorMessage = ' Incorrect username or password. Please try again.'
91+
92+ this .password = ' '
93+
94+ this .$nextTick (() => {
95+ this .$refs .passwordField .$el .querySelector (' input' ).focus ()
96+ })
9497
9598 this .loggingIn = false
9699 })
@@ -102,7 +105,6 @@ export default {
102105<style lang="css" scoped>
103106.card-width {
104107 width : 477px ;
105-
106108}
107109
108110@media (max-width : 620px ) {
0 commit comments