-
Notifications
You must be signed in to change notification settings - Fork 39
Description
Hi. Thans for your great work!
I am currently facing an issue of components trying to access session.user before it is ready to be accessed. The problem is that initSessionService calls loadUser in an async manner ( which is perfectly fine), thus, session.user can be accessed when it is not ready.
An example code is show below (Note that unimportant codes are abbreviated).
index.js
sessionService.initSessionService(store, {driver: 'COOKIES'} );
render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
)App.js
export const App = ({session}) => {
doSomethingWithUserInfo(session.user)
...
}
const mapStateToProps = ({session}) => ({
session,
});
export default connect(mapStateToProps)(App)To avoid this problem, I want to make sure that session.user is set before proceeding to the next lines.
One way to achieve this is to return Promise in initSessionService and modify refreshFromLocalStorage a bit (so that it returns the promise that corresponds to loadUser).
If you have another way of solving this issue, please let me know. Otherwise, I am willing to issue an PR!
Thanks!