eztech-core-components 1.0.2 → 1.0.3
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/plugins/axios.js +9 -0
- package/store/user.js +24 -23
package/package.json
CHANGED
package/plugins/axios.js
CHANGED
|
@@ -20,9 +20,18 @@ export default ({ $axios, query, store, $cookies, redirect, i18n, route, params,
|
|
|
20
20
|
// delete $axios.defaults.headers.common.Authorization
|
|
21
21
|
// }
|
|
22
22
|
const tokenName = store.getters['user/tokenName']
|
|
23
|
+
const authType = store.getters['user/authType']
|
|
23
24
|
if (tokenName) {
|
|
24
25
|
$axios.defaults.headers.common['x-pid'] = tokenName
|
|
25
26
|
}
|
|
27
|
+
console.log('authType', authType)
|
|
28
|
+
if (authType === 'header') {
|
|
29
|
+
$axios.defaults.headers.common['x-at'] = authType
|
|
30
|
+
const userToken = store.getters['user/token']
|
|
31
|
+
if (userToken) {
|
|
32
|
+
$axios.defaults.headers.common['Autherization'] = `Bearer ${userToken}`
|
|
33
|
+
}
|
|
34
|
+
}
|
|
26
35
|
$axios.defaults.headers.common['Accept-Language'] = query.lang || i18n?.locale || 'mn'
|
|
27
36
|
return config
|
|
28
37
|
})
|
package/store/user.js
CHANGED
|
@@ -9,29 +9,21 @@ export const state = () => ({
|
|
|
9
9
|
notificationCount: 0,
|
|
10
10
|
notificationList: [],
|
|
11
11
|
isLocked: false,
|
|
12
|
-
loginProps: null
|
|
12
|
+
loginProps: null,
|
|
13
|
+
authType: 'cookie'
|
|
13
14
|
})
|
|
14
15
|
|
|
15
16
|
export const getters = {
|
|
16
|
-
user (state) {
|
|
17
|
-
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
},
|
|
22
|
-
tokenName (state) {
|
|
23
|
-
return state.tokenName
|
|
24
|
-
},
|
|
25
|
-
hideProfile (state) {
|
|
26
|
-
return state.hideProfile
|
|
27
|
-
},
|
|
28
|
-
projectId (state) {
|
|
29
|
-
return state.projectId
|
|
30
|
-
},
|
|
17
|
+
user (state) { return state.user },
|
|
18
|
+
token (state) { return state.token },
|
|
19
|
+
tokenName (state) { return state.tokenName },
|
|
20
|
+
hideProfile (state) { return state.hideProfile },
|
|
21
|
+
projectId (state) { return state.projectId },
|
|
31
22
|
notificationCount (state) { return state.notificationCount },
|
|
32
23
|
notificationList (state) { return state.notificationList },
|
|
33
24
|
isLocked (state) { return state.isLocked },
|
|
34
|
-
loginProps (state) { return state.loginProps }
|
|
25
|
+
loginProps (state) { return state.loginProps },
|
|
26
|
+
authType (state) { return state.authType }
|
|
35
27
|
}
|
|
36
28
|
|
|
37
29
|
export const mutations = {
|
|
@@ -64,6 +56,9 @@ export const mutations = {
|
|
|
64
56
|
},
|
|
65
57
|
SET_LOGIN_PROPS (state, val) {
|
|
66
58
|
state.loginProps = val
|
|
59
|
+
},
|
|
60
|
+
SET_AUTH_TYPE (state, val) {
|
|
61
|
+
state.authType = val
|
|
67
62
|
}
|
|
68
63
|
}
|
|
69
64
|
|
|
@@ -72,10 +67,14 @@ export const actions = {
|
|
|
72
67
|
const tokenName = process.env.TOKEN_NAME || null
|
|
73
68
|
const projectId = process.env.PROJECT_ID
|
|
74
69
|
const loginProps = process.env.LOGIN_PROPS
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
const authType = process.env.AUTH_TYPE || 'cookie'
|
|
71
|
+
if (authType === 'header') {
|
|
72
|
+
commit('SET_AUTH_TYPE', 'header')
|
|
73
|
+
const token = query[tokenName] || $cookies.get(tokenName)
|
|
74
|
+
if (token) {
|
|
75
|
+
commit('SET_TOKEN', token)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
79
78
|
commit('SET_LOGIN_PROPS', loginProps)
|
|
80
79
|
commit('SET_TOKEN_NAME', tokenName)
|
|
81
80
|
commit('SET_PROJECT_ID', projectId)
|
|
@@ -163,8 +162,10 @@ export const actions = {
|
|
|
163
162
|
commit('SET_HIDE_PROFILE', value)
|
|
164
163
|
},
|
|
165
164
|
set_token ({ commit, getters }, token) {
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
if (getters.authType === 'header') {
|
|
166
|
+
const tokenOptions = { maxAge: 60 * 60 * 24 * 7, path: '/' }
|
|
167
|
+
this.$cookies.set(getters.tokenName, token, tokenOptions)
|
|
168
|
+
}
|
|
168
169
|
commit('SET_TOKEN', token)
|
|
169
170
|
if (process.client) {
|
|
170
171
|
localStorage.setItem('forensic_checkLogin', Date.now())
|