orderiom-api-package 0.4.100 → 0.4.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/common.js +5 -0
- package/src/modules/auth.js +10 -0
package/package.json
CHANGED
package/src/common.js
CHANGED
|
@@ -167,6 +167,8 @@ const getAuthToken = async ($store, hadPrivateToken = false) => {
|
|
|
167
167
|
axios.defaults.baseURL = process.env.VUE_APP_BASE_API_URL || window.dynamicData.VUE_APP_BASE_API_URL;
|
|
168
168
|
export const defineInterceptors = ({$store}) => {
|
|
169
169
|
axios.interceptors.request.use(config => {
|
|
170
|
+
$store.dispatch('auth/startRequesting');
|
|
171
|
+
|
|
170
172
|
// exception API that does not need any pre-process
|
|
171
173
|
if(config.url === getTokenAPI) return config;
|
|
172
174
|
|
|
@@ -221,11 +223,13 @@ export const defineInterceptors = ({$store}) => {
|
|
|
221
223
|
if(!isFetchingToken) getAuthToken($store, hadPrivateToken);
|
|
222
224
|
})
|
|
223
225
|
}, error => {
|
|
226
|
+
$store.dispatch('auth/finishRequesting');
|
|
224
227
|
return Promise.reject(error);
|
|
225
228
|
});
|
|
226
229
|
|
|
227
230
|
axios.interceptors.response.use(
|
|
228
231
|
res => {
|
|
232
|
+
$store.dispatch('auth/finishRequesting');
|
|
229
233
|
return {
|
|
230
234
|
type: 'success',
|
|
231
235
|
msg: '',
|
|
@@ -234,6 +238,7 @@ export const defineInterceptors = ({$store}) => {
|
|
|
234
238
|
}
|
|
235
239
|
},
|
|
236
240
|
error => {
|
|
241
|
+
$store.dispatch('auth/finishRequesting');
|
|
237
242
|
if (
|
|
238
243
|
error.response &&
|
|
239
244
|
error.response.data &&
|
package/src/modules/auth.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {commonErrorCallback, $http, restaurantIdEnv, isTokenExpired} from '../common';
|
|
2
2
|
|
|
3
3
|
const state = {
|
|
4
|
+
isRequesting: false,
|
|
4
5
|
user: {},
|
|
5
6
|
restaurantInfo: {},
|
|
6
7
|
email: null,
|
|
@@ -17,6 +18,9 @@ const getters = {
|
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
const mutations = {
|
|
21
|
+
setIsRequesting(state, value){
|
|
22
|
+
state.isRequesting = value;
|
|
23
|
+
},
|
|
20
24
|
storeUser(state, userData) {
|
|
21
25
|
state.user = userData
|
|
22
26
|
},
|
|
@@ -50,6 +54,12 @@ const actions = {
|
|
|
50
54
|
auth({}) {
|
|
51
55
|
console.warn('auth/auth action is deprecated. No need to call');
|
|
52
56
|
},
|
|
57
|
+
startRequesting({commit}){
|
|
58
|
+
commit('setIsRequesting', true)
|
|
59
|
+
},
|
|
60
|
+
finishRequesting({commit}){
|
|
61
|
+
commit('setIsRequesting', false)
|
|
62
|
+
},
|
|
53
63
|
login({commit, dispatch}, authData) {
|
|
54
64
|
var data = {...authData};
|
|
55
65
|
if (authData.ordermood) {
|