Last active
May 27, 2020 15:01
-
-
Save IlyaDonskikh/d31b354691bd7bad84342973a59f9bfb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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