Fix problem with missing loginData

This commit is contained in:
Peter Stuifzand 2018-08-29 16:02:49 +02:00
parent 31ae5c7e65
commit 6d8e657fc5
4 changed files with 13 additions and 6 deletions

View File

@ -14,3 +14,4 @@ Some features that need to be implemented
- Better responsive interface - Better responsive interface
- Websockets? Show new channels and new items in channels directly, needs - Websockets? Show new channels and new items in channels directly, needs
micropub server support micropub server support
- Improve handling of entries with missing values (like missing author)

View File

@ -31,8 +31,11 @@
name: 'App', name: 'App',
components: {LoginModal}, components: {LoginModal},
mounted() { mounted() {
let loginData = JSON.parse(window.localStorage.getItem('login_data')) let item = window.localStorage.getItem('login_data');
this.$store.dispatch('isLoggedIn', loginData) if (item) {
let loginData = JSON.parse(item)
this.$store.dispatch('isLoggedIn', loginData)
}
} }
} }
</script> </script>

View File

@ -84,7 +84,7 @@
}).then(response => response.json()) }).then(response => response.json())
.then(response => { .then(response => {
this.$store.dispatch('tokenResponse', response) this.$store.dispatch('tokenResponse', response)
this.active = false this.show = false
this.$router.push('/') this.$router.push('/')
}) })
} }

View File

@ -8,14 +8,17 @@ Vue.use(Vuex)
export default new Vuex.Store({ export default new Vuex.Store({
state() { state() {
let loginData = JSON.parse(window.localStorage.getItem('login_data')) let loginData = JSON.parse(window.localStorage.getItem('login_data'))
return { let newState = {
...loginData,
channels: [], channels: [],
timeline: {items: [], paging: {}}, timeline: {items: [], paging: {}},
channel: {}, channel: {},
debug: false, debug: false,
logged_in: loginData.access_token && loginData.access_token.length > 0 };
if (loginData) {
newState = { ...newState, ...loginData }
newState.logged_in = loginData.access_token && loginData.access_token.length > 0
} }
return newState
}, },
mutations: { mutations: {