Firebase Initializing Without Auth - firebase.auth is not a function

冷暖自知 提交于 2019-12-06 05:04:45

Update: I started encountering this error again recently. Firebase was initializing without Auth again (see image). It seemed to happen sporadically when I updated or re-installed my node_modules.

I posted an updated answer at the following link for a similar question - which also lists several other potential solutions other people experimented with. My fix involves completely removing npm, nvm, and node from my Mac, and doing a clean install with nvm: firebase.auth is not a function


I struggled with this for 3 days, trying all sorts of different ways of implementing the sdk, exactly as according to documentation, and many other examples, and finally found an example that worked. This git repository has a great, and very simple example that was similar to my react-router v4 setup. tylermcginnis/react-router-firebase-auth

Essentially, I made my implementation as follows

firebase.js I moved the firebase configuration code to a separate file, and then exported firebase.auth as a constant called firebaseAuth.

import firebase from 'firebase'

const config = {
  apiKey: "AIza....pPk",
  authDomain: "project.firebaseapp.com",
  databaseURL: "https://project.firebaseio.com",
}

firebase.initializeApp(config)

export const firebaseAuth = firebase.auth

Redux Actions / Where it's Used I am using redux to handle the various actions than can happen with my components. In my actions file, I am importing the firebaseAuth variable, and using that to call the various firebase auth functions. As you can see here, firebaseAuth() is called as a function.

This successfully created the user in my firebase project. (I am aware that everything is labeled "signIn", but it's using the create account function).

import { firebaseAuth } from '../../config/firebase'
/**
 * Sign In User
 * Signs in our end user using firebase auth
 */

export const signIn = () => {
    return (dispatch, getState) => {
        console.log("Sign In - In Progress");
        // Get the state from the redux store
        const reduxState = getState();

        let email = reduxState.form.signIn.values.email;
        let password = reduxState.form.signIn.values.password;

        firebaseAuth().createUserWithEmailAndPassword(email, password).catch(function(error) {
            // Handle Errors here.
            console.log("Login Errors: " + error.code + error.message);
            // ...
        });
    }
}

By the way, I am using redux-form for user content entry, and redux-thunk middleware to have dispatch and getState in the actions.

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