mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
client: load user based on localStorage (only for testing) (#8055)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
#app
|
#app
|
||||||
site-header
|
site-header
|
||||||
p Welcome back {{user.profile.name}}
|
p Welcome back {{user.profile.name}}!
|
||||||
ul
|
ul
|
||||||
li
|
li
|
||||||
router-link(to='/') Home
|
router-link(to='/') Home
|
||||||
|
|||||||
@@ -10,8 +10,16 @@ import router from './router';
|
|||||||
import store from './vuex/store';
|
import store from './vuex/store';
|
||||||
|
|
||||||
Vue.use(VueResource);
|
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
|
// Sync Vuex and Router
|
||||||
VuexRouterSync.sync(store, router);
|
VuexRouterSync.sync(store, router);
|
||||||
@@ -38,3 +46,9 @@ let userWatcher = store.watch(state => state.user, (user) => {
|
|||||||
app.$mount('#app');
|
app.$mount('#app');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Load the user
|
||||||
|
store.dispatch('fetchUser')
|
||||||
|
.catch(() => {
|
||||||
|
alert('Impossible to fetch user. Copy into localStorage a valid habit-mobile-settings object.');
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user