skip to Main Content

ReferenceError: Can’t find variable: auth

please help

const handleLogin = () => {
    auth
      .signInWithEmailAndPassword(email, password)
      .then(userCredentials => {
        const user = userCredentials.user;
        console.log('Logged in with:', user.email);
      })
      .catch(error => alert(error.message))
  }

3

Answers


  1. Where do you expect auth to come from?

    If you’re following the Firebase documentation, the getting started page initialized an auth variable as:

    // Initialize Firebase Authentication and get a reference to the service
    const auth = firebase.auth();
    
    Login or Signup to reply.
  2. Install @react-native-firebase/auth from

    npm install @react-native-firebase/auth

    and import

    import auth from '@react-native-firebase/auth'

    Login or Signup to reply.
  3. Install firebase/auth package
    and import auth package in the component where it used
    for details, refer to this link https://rnfirebase.io/auth/usage

    and it should be like this
    auth().signInWithEmailAndPassword(email, password)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search