Add session_established flag in global store
				
					
				
			This commit is contained in:
		
							parent
							
								
									777f877dd5
								
							
						
					
					
						commit
						a80a42fb56
					
				
					 2 changed files with 8 additions and 23 deletions
				
			
		| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
<template>
 | 
			
		||||
  <!-- note, we do not show anything at all until we have user info -->
 | 
			
		||||
  <div class="main-container" v-show="fetchedUserInfo">
 | 
			
		||||
  <div class="main-container" v-show="$store.state.session_established">
 | 
			
		||||
    <slot>
 | 
			
		||||
      <p>TODO: put your nav in the default slot!</p>
 | 
			
		||||
    </slot>
 | 
			
		||||
| 
						 | 
				
			
			@ -28,12 +28,6 @@ export default {
 | 
			
		|||
            default: true,
 | 
			
		||||
        },
 | 
			
		||||
    },
 | 
			
		||||
    data() {
 | 
			
		||||
        return {
 | 
			
		||||
            // we will not display anything until we have user info
 | 
			
		||||
            'fetchedUserInfo': false,
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    beforeCreate: function() {
 | 
			
		||||
 | 
			
		||||
        // TODO: even with beforeCreate() this logic is still happening "too
 | 
			
		||||
| 
						 | 
				
			
			@ -54,27 +48,14 @@ export default {
 | 
			
		|||
            // also keep track of user's permissions
 | 
			
		||||
            this.$store.commit('SET_PERMISSIONS', response.data.permissions)
 | 
			
		||||
 | 
			
		||||
            // if user is anonymous, and requested logout page, send to login instead
 | 
			
		||||
            // TODO: remove this
 | 
			
		||||
            if (!response.data.user && this.$route.name == 'logout') {
 | 
			
		||||
                this.$router.push('/login')
 | 
			
		||||
            }
 | 
			
		||||
            // declare the session established
 | 
			
		||||
            this.$store.commit('SET_SESSION_ESTABLISHED', true)
 | 
			
		||||
 | 
			
		||||
            // set background color, to whatever api said
 | 
			
		||||
            // TODO: should this be the custom app's responsibility?
 | 
			
		||||
            if (response.data.background_color) {
 | 
			
		||||
                document.body.style.backgroundColor = response.data.background_color
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // okay now we can let the app display.  if this page needs to
 | 
			
		||||
            // redirect based on new info, that should have happened by now?
 | 
			
		||||
            this.fetchedUserInfo = true
 | 
			
		||||
 | 
			
		||||
        }, response => { // error handler
 | 
			
		||||
 | 
			
		||||
            // pretend that we *did* get user info, just so something displays
 | 
			
		||||
            // TODO: should probably show some kind of warning also
 | 
			
		||||
            this.fetchedUserInfo = true
 | 
			
		||||
        })
 | 
			
		||||
    },
 | 
			
		||||
    mounted: function () {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue