1

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!!

maicss
  • 69
  • 8
  • I'm not sure to understand, feel free to correct me: when user reload the page, it stays logged ? – Kmaschta Feb 14 '19 at 08:41
  • no. because the http client (websocket client) I use is `asteroid`, it has a `resumeLogin` method, but not exposed, I cannot get the login done promise. And I fork it and exposed `resumeLogin` method as a promise. so I used the here : `return asteroid.resumeLogin().then(account => blabla)` ------------------------------------------------------------------------------------------------------------ and even I use other http client, reload some page, still not login, right? I do not want use local cached token as use logged in. – maicss Feb 15 '19 at 16:06

0 Answers0