client: load user based on localStorage (only for testing) (#8055)

This commit is contained in:
Matteo Pagliazzi
2016-09-23 22:39:06 +02:00
committed by GitHub
parent 633da7ff73
commit bccdf4e989
2 changed files with 17 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
<template lang="pug">
#app
site-header
p Welcome back {{user.profile.name}}
p Welcome back {{user.profile.name}}!
ul
li
router-link(to='/') Home

View File

@@ -10,8 +10,16 @@ import router from './router';
import store from './vuex/store';
Vue.use(VueResource);
Vue.http.headers.common['x-api-user'] = '';
Vue.http.headers.common['x-api-key'] = '';
// TODO just for the beginning
let authSettings = localStorage.getItem('habit-mobile-settings');
if (authSettings) {
authSettings = JSON.parse(authSettings);
Vue.http.headers.common['x-api-user'] = authSettings.auth.apiId;
Vue.http.headers.common['x-api-key'] = authSettings.auth.apiToken;
}
// Sync Vuex and Router
VuexRouterSync.sync(store, router);
@@ -38,3 +46,9 @@ let userWatcher = store.watch(state => state.user, (user) => {
app.$mount('#app');
}
});
// Load the user
store.dispatch('fetchUser')
.catch(() => {
alert('Impossible to fetch user. Copy into localStorage a valid habit-mobile-settings object.');
});