Home>

I'm creating an application using Vue.

Originally, when you log in, "Logged in" is displayed in the upper right corner of the screen, and when you log out, "Logged out" is displayed.
However, when I open the application, the message "Logped out" is displayed.

<script>
// import HelloWorld from'./components/HelloWorld.vue'
import firebase from'firebase'
import {mapActions, mapGetters} from'vuex'
export default {
  name:'app',
  // components: {
  // Hello World
  //}
  beforeCreate () {
    firebase.auth (). onAuthStateChanged (user =>{
      if (user) {
        // Set the user information in the store state and display "Logged in"
        this.setLoginUser (user)
        this.fetchBooks ()
        this.fetchOthersBooks ()
        this. $Router.push ('/')
        this. $notify ({
        title:'Book Recorder',
        message: this. $createElement ('p', {style:'color: # 009'},'logged in'),
        duration: 2000
      })
      } else {
        // Delete user information from store state and display "Logged out"
        this.deleteLoginUser ()
        this. $Router.push ('/')
        this. $notify ({
          title:'Book Recorder',
          message: this. $createElement ('p', {style:'color: # 009'},'logged out'),
          duration: 2000
        })
      }
    })
  },
  methods: {
    ... mapActions (['setLoginUser','deleteLoginUser','logout','fetchBooks','fetchOthersBooks'])
  },
  computed: {
    ... mapGetters (['userName','photoUrl'])
  }
}
</script>

Is it possible to display the logout notification only when I log out?

  • Answer # 1

    With the current implementationWhen "user" is falseTologged outIt is because it is displayed as.

    If only when you log outThe user was true in advanceAndI have never displayed that I have logged outIt seems that it will be solved if conditions such as time are added.

Related articles