mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-05-19 04:08:54 +00:00
client: load user based on localStorage (only for testing) (#8055)
This commit is contained in:
parent
633da7ff73
commit
bccdf4e989
2 changed files with 17 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.');
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue