Darren
Darren

Reputation: 2290

firebase.auth().setPersistence error of 'Persistence' of undefined

I am using Firebase auth to handle authentication of users in a form but am getting this error

error of 'Persistence' of undefined

when adding firebase.auth().setPersistence.

onSubmit = event => {
  const { firebase } = this.props;
  const { email, password, remember } = this.state;
  firebase
    .doSignInWithEmailAndPassword(email, password, remember)
    .then(authUser => {
      firebase.doEmailUpdateUser(authUser);
    })
    .then(() => {
      this.setState({ error: null });
      navigate(ROUTES.INDEX);
    })
    .catch(error => {
      this.setState({
        error,
        errorOpen: true
      });
    });

  event.preventDefault();
};

Whereas firebase.doSignInWithEmailAndPassword(email, password, remember) is

doSignInWithEmailAndPassword = (email, password, remember) => {
  this.auth
    .setPersistence(
      `${
        remember
          ? this.auth.Auth.Persistence.LOCAL
          : this.auth.Auth.Persistence.SESSION
      }`
    )
    .then(() => this.auth.signInWithEmailAndPassword(email, password));
};

for reference this.auth = app.auth();

Have I missed something here? What have I done wrong?

Upvotes: 1

Views: 1637

Answers (1)

Nicholas Tower
Nicholas Tower

Reputation: 84902

Looks like you're trying to get Auth.Persistence from the wrong object. You say this.auth = app.auth(), so i assume then that app was imported from firebase something like import app from 'firebase'. If that's incorrect, please show me how you're importing.

If my assumptions were correct, then you'll need to access the properties like app.auth.Auth.Persistence.LOCAL. Your current version is more like app.auth().Auth.Persistence.LOCAL

Upvotes: 2

Related Questions