mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-05-31 14:11:58 +05:30
Init user state before app initialization. Moved i18n logic into coresponding service
This commit is contained in:
22
src/components/user/factory.js
Normal file
22
src/components/user/factory.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { authenticate } from 'components/user/actions';
|
||||
|
||||
/**
|
||||
* Initializes User state with the fresh data
|
||||
*
|
||||
* @param {Object} store - redux store
|
||||
*
|
||||
* @return {Promise} a promise, that resolves in User state
|
||||
*/
|
||||
export function factory(store) {
|
||||
const state = store.getState();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if (state.user.token) {
|
||||
// authorizing user if it is possible
|
||||
store.dispatch(authenticate(state.user.token))
|
||||
.then(() => resolve(store.getState().user), reject);
|
||||
} else {
|
||||
resolve(state.user);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user