|
|
|
@ -58,22 +58,24 @@ const initialState = {
|
|
|
|
|
permissionList: []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const useAuthStore = create(lifecycleware((set, get) => ({
|
|
|
|
|
const useAuthStore = create((set, get) => ({
|
|
|
|
|
|
|
|
|
|
...initialState,
|
|
|
|
|
|
|
|
|
|
onAuth: async () => {
|
|
|
|
|
initAuth: async () => {
|
|
|
|
|
const { startTokenInterval, loadUserPermission } = get()
|
|
|
|
|
const { setStorage, loginToken } = usingStorage()
|
|
|
|
|
|
|
|
|
|
appendRequestParams('token', loginToken)
|
|
|
|
|
const userJson = await fetchUserDetail(loginToken)
|
|
|
|
|
|
|
|
|
|
appendRequestParams('token', loginToken)
|
|
|
|
|
appendRequestParams('lmi_sn', userJson.LMI_SN)
|
|
|
|
|
|
|
|
|
|
setStorage(KEY_USER_ID, userJson.LMI_SN)
|
|
|
|
|
setStorage(KEY_TRAVEL_AGENCY_ID, userJson.LMI_VEI_SN)
|
|
|
|
|
|
|
|
|
|
await loadUserPermission(userJson.LMI_SN)
|
|
|
|
|
|
|
|
|
|
set(() => ({
|
|
|
|
|
currentUser: {
|
|
|
|
|
username: userJson.LoginName,
|
|
|
|
@ -84,20 +86,19 @@ const useAuthStore = create(lifecycleware((set, get) => ({
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
await loadUserPermission(userJson.LMI_SN)
|
|
|
|
|
startTokenInterval()
|
|
|
|
|
loadPageSpy(userJson.real_name)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
authenticate: async (usr, pwd) => {
|
|
|
|
|
const { onAuth } = get()
|
|
|
|
|
const { onRefresh } = get()
|
|
|
|
|
const { setStorage } = usingStorage()
|
|
|
|
|
|
|
|
|
|
const { token: loginToken } = await fetchLoginToken(usr, pwd)
|
|
|
|
|
|
|
|
|
|
setStorage(KEY_LOGIN_TOKEN, loginToken)
|
|
|
|
|
|
|
|
|
|
await onAuth()
|
|
|
|
|
await initAuth()
|
|
|
|
|
|
|
|
|
|
set(() => ({
|
|
|
|
|
tokenTimeout: false,
|
|
|
|
@ -190,6 +191,6 @@ const useAuthStore = create(lifecycleware((set, get) => ({
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
})))
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
export default useAuthStore
|