Firebase Auth - User not logged in after Firebase sign up and redirect

℡╲_俬逩灬. 提交于 2019-12-05 13:23:18

I have the same setup and it works fine.

I have my auth state change listener at the top of my router...

state = { user: null };

componentDidMount() {
   firebase.auth().onAuthStateChanged(user => {
      if (user) {
        this.setState({ user });
      } else {
        this.props.history.push('/login');
      }
   });
 }

In Login.js I have a form that connects to a login function similar to yours...

login() {
    firebase
      .auth()
      .signInWithEmailAndPassword(this.state.email, this.state.password)
      .then(res => {
        this.props.history.push('/');
      })
      .catch(err => console.error(error));
  }

The only thing that I can think of you gave history.replace, try changing to history.push.

If that doesn't work is there any chance you can set up a https://codesandbox.io/ with a mcve and I'd be happy to debug it https://stackoverflow.com/help/mcve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!