when user login, I got user's info, and save its token to localstorage, and save account info to global store by customSaga.
when user reload page, react-admin
will dispatch an action AUTH_CHECH
, so I login user by localstorage token, then save its account info to store, the best solution likes:
// in authProvider
case AUTH_CHECK:
if (token) {
return httpClient.loginWithToken()
.then(account => store.dispatch({USER_LOGIN_SUCCESS, payload: account}))
} else {
return history.push('/login')
}
but as François Zaninotto said, I should watch some action and write some saga to watch this:
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})
})
And react-admin
not export his store: https://github.com/marmelab/react-admin/blob/master/packages/ra-core/src/CoreAdmin.tsx#L153
So how to solve this problem?
Thanks!!