Skip to content

Commit

Permalink
init i18n and pre authentication in parallel, fix jwt selector
Browse files Browse the repository at this point in the history
  • Loading branch information
FredericHeem committed Aug 27, 2016
1 parent 0641862 commit 82849d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
25 changes: 19 additions & 6 deletions client/src/app/app.js
Expand Up @@ -46,6 +46,21 @@ export default function() {

rest.setJwtSelector(jwt.selector(store));

async function i18nInit() {
const language = await i18n.load();
context.formatter.setLocale(language);
store.dispatch(parts.core.actions.setLocale(language))
await intl(language);
}

async function preAuth() {
let token = localStorage.getItem("JWT");
if (token) {
store.dispatch(parts.auth.actions.setToken(token))
await store.dispatch(parts.auth.actions.me())
}
}

return {
parts,
store,
Expand All @@ -54,12 +69,10 @@ export default function() {
},
async start() {
debug("start");
const language = await i18n.load();
context.formatter.setLocale(language);
store.dispatch(parts.core.actions.setLocale(language))
await intl(language);
jwt.loadJWT(parts);
store.dispatch(parts.auth.actions.me())
return Promise.all([
i18nInit(),
preAuth()
]);
}
};
}
9 changes: 1 addition & 8 deletions client/src/app/utils/jwt.js
@@ -1,14 +1,7 @@
export default function(store) {
return {
loadJWT(parts) {
let token = localStorage.getItem("JWT");
if (token) {
store.dispatch(parts.auth.actions.setToken(token))
}
return token;
},
selector() {
return () => store.getState().auth.token
return () => store.getState().auth.auth.token
}
}
}

0 comments on commit 82849d2

Please sign in to comment.