aboutsummaryrefslogtreecommitdiff
path: root/src/site/pages/login.vue
diff options
context:
space:
mode:
authorPitu <[email protected]>2019-03-29 00:35:58 +0900
committerPitu <[email protected]>2019-03-29 00:35:58 +0900
commitea3e503d13b7be477c064b02b9b2e5a9ef06c9a9 (patch)
tree8ffd0bef5e2e210ca28478d18c3876b73cc79784 /src/site/pages/login.vue
parentAdded axios package (diff)
downloadhost.fuwn.me-ea3e503d13b7be477c064b02b9b2e5a9ef06c9a9.tar.xz
host.fuwn.me-ea3e503d13b7be477c064b02b9b2e5a9ef06c9a9.zip
Added middleware for pages and switched to $axios
Diffstat (limited to 'src/site/pages/login.vue')
-rw-r--r--src/site/pages/login.vue31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/site/pages/login.vue b/src/site/pages/login.vue
index fe7d64a..c713674 100644
--- a/src/site/pages/login.vue
+++ b/src/site/pages/login.vue
@@ -95,32 +95,27 @@ export default {
return { title: 'Login' };
},
methods: {
- login() {
+ async login() {
if (this.isLoading) return;
if (!this.username || !this.password) {
this.$showToast('Please fill both fields before attempting to log in.', true);
return;
}
this.isLoading = true;
- this.axios.post(`${this.config.baseURL}/auth/login`, {
- username: this.username,
- password: this.password
- }).then(res => {
- this.$store.commit('token', res.data.token);
- this.$store.commit('user', res.data.user);
- /*
- if (res.data.mfa) {
- this.isMfaModalActive = true;
- this.isLoading = false;
- } else {
- this.getUserData();
- }
- */
+
+ try {
+ const data = await this.$axios.$post(`auth/login`, {
+ username: this.username,
+ password: this.password
+ });
+ this.$axios.setToken(data.token, 'Bearer');
+ this.$store.dispatch('login', { token: data.token, user: data.user });
this.redirect();
- }).catch(err => {
+ } catch (error) {
+ this.$onPromiseError(error);
+ } finally {
this.isLoading = false;
- this.$onPromiseError(err);
- });
+ }
},
/*
mfa() {