chrisbraddock / vuefire-auth-demo

demo vuefire and Firebase authentication
MIT License
43 stars 1 forks source link

Question about the example #1

Open Frondor opened 7 years ago

Frondor commented 7 years ago

What does .bind(this) means on this line https://github.com/chrisbraddock/vuefire-auth-demo/blob/master/index.html#L50 ? What are why binding and where?

Also, I'm trying to get auth states working on a test app, and I'm checking whether user is logged in or not by calling this.$router.app.user on a child component (App.vue from Vue CLI) since I'm using vue-router, is it ok for you?

mornir commented 7 years ago

Hi Frondor! Just stick to using ES6 features (arrow functions, let/const, object-shorthands) and you will encounter less problems with scopes.

firebase.auth().onAuthStateChanged(user => {
          if (user) {
            this.user = user
            this.$bindAsArray('messages', db.ref('messages/' + user.uid))
          } else {
            firebase.auth().signInAnonymously().catch(console.error)
          }
        })