Skip to content

Instantly share code, notes, and snippets.

@IlyaDonskikh
Last active May 27, 2020 15:01
Show Gist options
  • Save IlyaDonskikh/d31b354691bd7bad84342973a59f9bfb to your computer and use it in GitHub Desktop.
Save IlyaDonskikh/d31b354691bd7bad84342973a59f9bfb to your computer and use it in GitHub Desktop.
async loginHandler(evt) {
evt.preventDefault()
this.loading = true // Use This later to show a spinner
this.error = false // Reset error message if one exists
// Options for the ApiRequest
const options = {
method: 'POST',
url: '/auth/sign_in',
data: this.form
}
try {
const apiResponse = await APIRequestHandler(options)
const response = await apiResponse.json()
// Check for an Error Flag
if (apiResponse.ok) {
this.$auth.setToken('local', response.user.token)
this.$auth.setUser(response.user)
// NOTE FOR SELF!
// Double Check that this works with multiple locales
// Push User to Dashboard Upon Auth
this.$router.push(this.localePath({ name: 'dashboard' }))
} else {
console.log(response.errors)
this.error = apiResponse.message
}
} catch (error) {
this.error = error.message
} finally {
this.loading = false
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment