Skip to content

Commit

Permalink
fix: not send req if validation failed
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkdo committed Apr 15, 2019
1 parent 1760310 commit e14bc9a
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions client/pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,24 @@ export default class Login extends Vue {
mounted() {
this.getCaptcha()
}
async login() {
login() {
const goBackTo = this.$route.query.page || '/'
this.logging = true
const valid = this.$refs.user.validate()
try {
if (valid) {
await this.$store.dispatch('login', this.user)
this.authenticated = await this.$store.getters.authenticated
}
} catch (e) {
this.$message.warning(e.message)
} finally {
if (this.authenticated) {
this.redirect(goBackTo)
this.$refs.user.validate(async (valid) => {
try {
if (valid) {
await this.$store.dispatch('login', this.user)
this.authenticated = await this.$store.getters.authenticated
}
} catch (e) {
this.$message.warning(e.message)
} finally {
if (this.authenticated) {
this.redirect(goBackTo)
}
}
}
this.logging = false
this.logging = false
})
}
redirect(goTo) {
this.$router.push(goTo)
Expand Down

0 comments on commit e14bc9a

Please sign in to comment.