score:1

Accepted answer

here's what happens:

  • webpage loads
  • firebase starts a request to check whether the user is authenticated
  • the app renders, currentuser is null
  • the authentication state changes, but the app doesn't re-render

the app needs to listen to changes in the authentication state and perform a re-render accordingly. https://firebase.google.com/docs/reference/js/firebase.auth.auth#onauthstatechanged

class app extends react.component {
  state = {
    currentuser: null
  }

  componentdidmount() {
    this.unsubscribe = firebase.auth().onauthstatechanged(currentuser => {
      this.setstate({ currentuser })
    })
  }

  componentwillunmount() {
    this.unsubscribe()
  }

  render() {
    // use this.state.currentuser
  }
}

Related Query

More Query from same tag