TypeError: firebase.auth().onUserChanged is not a function

Hello everyone,

I hope you’re well.
I am developing an app with expo and firebase and I run into the following error “TypeError: firebase.auth (). OnUserChanged is not a function” and I do not understand why? if I previously install firebase, the login and registration of users with firebase is working fine. But that function I want to do to validate that the user is logged in and if so send it to the menu of the app (home of the app) or otherwise send it to auth menu (the login / registration) I’m getting the indicated error. Below the code:

// import liraries
import React, { Component } from 'react';
import { View } from 'react-native';
import * as firebase from 'firebase';

require('firebase/auth');

// create a component
class AuthLoading extends Component {
  componentDidMount() {
    this.getUser();
  }

  getUser() {
    firebase.auth().onUserChanged((user) => {
      this.props.navigation.navigate(user ? 'App' : 'Auth');
    });
  }

  render() {
    return <View />;
  }
}

// make this component available to the app
export default AuthLoading;

Attache capture of error:
1

I’ll appreciate your help
Thanks
Regards

maybe try auth().onAuthStateChanged

Hey @pixsolution,

It looks like deleting and re-installing node_modules might be the trick here as described in this SO post.

Remember to please make sure you’re searching on google (or whatever search engine you prefer) before posting as you’ll often find an answer without ever needing to create a forum post.

Cheers,
Adam

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.