ソースを参照

Changed the pormise on the login

master
Lene Scholtz 5年前
コミット
a45a9ddc96
2個のファイルの変更31行の追加30行の削除
  1. 9
    0
      src/components/user/loginPage.vue
  2. 22
    30
      src/store/modules/user/authentication.js

+ 9
- 0
src/components/user/loginPage.vue ファイルの表示

@@ -129,9 +129,18 @@ export default {
129 129
       } else this.troubleToggle = true;
130 130
     },
131 131
     Login() {
132
+      console.log(this.$store.state.authentication);
133
+
132 134
       this.login().then(() => {
135
+        console.log('this');
136
+        console.log(this);
137
+        console.log(this.$store.state.authentication.status);
138
+
133 139
         if (this.$store.state.authentication.status === 'error') {
134 140
           this.$router.push('/user/login');
141
+        } else {
142
+          console.log('yippy tequila');
143
+          this.$router.push('/about/us');
135 144
         }
136 145
       });
137 146
     },

+ 22
- 30
src/store/modules/user/authentication.js ファイルの表示

@@ -53,9 +53,7 @@ export default {
53 53
     authStatus: state => state.status,
54 54
   },
55 55
   actions: {
56
-    init({
57
-      commit,
58
-    }) {
56
+    init({ commit }) {
59 57
       if (!log.isLoggedIn() && log.tokenExpired) {
60 58
         log.clearValues();
61 59
       } else log.updateTokenExpiry();
@@ -66,37 +64,31 @@ export default {
66 64
         agency: log.getJSONObject('agency'),
67 65
       });
68 66
     },
69
-    login({
70
-      commit,
71
-      state,
72
-    }) {
73
-      return new Promise((reject) => {
74
-        commit('auth_request');
75
-        const user = {
67
+    login({ commit, state }) {
68
+      axios({
69
+        url: '/api/register/authenticate',
70
+        data: {
76 71
           username: state.username,
77 72
           password: state.password,
78
-        };
79
-        axios({
80
-          url: '/api/register/authenticate',
81
-          data: user,
82
-          method: 'POST',
73
+        },
74
+        method: 'POST',
75
+      })
76
+        .then((resp) => {
77
+          log.clearValues();
78
+          log.setValues(resp.data);
79
+          console.log(resp.data);
80
+
81
+          commit('auth_success', resp.data);
83 82
         })
84
-          .then((resp) => {
85
-            log.clearValues();
86
-            log.setValues(resp.data);
87
-            commit('auth_success', resp.data);
88
-          })
89
-          .catch((err) => {
90
-            commit('auth_error');
91
-            log.clearValues();
92
-            reject(err);
93
-            commit('auth_error', err.data);
94
-          });
95
-      });
83
+        .catch((err) => {
84
+          commit('auth_error');
85
+          log.clearValues();
86
+          // reject(err);
87
+          commit('auth_error', err.data);
88
+        });
89
+      /* }); */
96 90
     },
97
-    logout({
98
-      commit,
99
-    }) {
91
+    logout({ commit }) {
100 92
       return new Promise(() => {
101 93
         commit('logout');
102 94
         log.clearValues();

読み込み中…
キャンセル
保存