当用户登录时,我获得了用户的信息,并将其令牌保存到localstorage,并通过customSaga将帐户信息保存到全球商店。
当用户重新加载页面时,react-admin
将调度操作AUTH_CHECH
,因此我使用localstorage令牌登录用户,然后将其帐户信息保存到存储中,最佳解决方案是:
// in authProvider
case AUTH_CHECK:
if (token) {
return httpClient.loginWithToken()
.then(account => store.dispatch({USER_LOGIN_SUCCESS, payload: account}))
} else {
return history.push('/login')
}
但是作为François Zaninotto said,我应该观看一些动作并写一些传奇来观看:
yield takeEvery(USER_CHECK, function * (payload) {
// console.log(payload)
// this will be something like: {route: "dashboard", routeParams: undefined}, and I cannot customized this payload
// in fact, even I can customized AUTH_CHECK payload, this will not solve my problem, because auth check is a promise, when action AUTH_CHECK dispathed, the result still not fetched.
yield put({type: USER_LOGIN_SUCCESS, userAccount})
})
react-admin
并没有导出他的商店:https://github.com/marmelab/react-admin/blob/master/packages/ra-core/src/CoreAdmin.tsx#L153
那么如何解决这个问题?
谢谢!