<template>
  <div id="app">
    <router-view/>

    <md-snackbar md-position="center" :md-duration="4000" :md-active.sync="showWelcome">
      <span>Welcome back {{ $store.state.auth.name }}!</span>
    </md-snackbar>
  </div>
</template>

<script>

import {mapState} from 'vuex';

export default {
  name: "App",
  data() {
    return {
      showWelcome: false
    }
  },
  computed: mapState('auth', ['name']),
  mounted() {
    this.$store.dispatch("auth/loadUserData").catch(() => {
      this.$router.push({name: "Welcome"});
    })
  },
  watch: {
    name(newValue, oldValue) {
      if (oldValue === '') {
        this.showWelcome = true;
      }
    }
  }
}
</script>

<style>
#app {
  height: 100vh;
}
</style>