Reputation: 335
I'm developing my very first React App and have encounter this error which I can't understand:
TypeError:firebase_firebase_utils_js__WEBPACK_IMPORTED_MODULE_7__.auth.onAuthStateChange is not a function
I have tried deleting my node_modules folder and reinstalling it. Also importing firebase with Node.js' require()
syntax. With no different result. I read some other StackOverflow articles that said something about 'firebase-admin' but I haven't installed such a dependency.
firebase.utils.js
import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';
const config = {...}
firebase.initializeApp(config);
export const auth = firebase.auth();
export const firestore = firebase.firestore();
const provider = new firebase.auth.GoogleAuthProvider();
provider.setCustomParameters({ prompt: 'select_account' });
export const signInWithGoogle = () => auth.signInWithPopup(provider);
export default firebase;
===================================
The code breaked when I added this: to my App.js
{...}
import { auth } from './firebase/firebase.utils.js';
class App extends React.Component {
constructor(){
super();
this.state = {
currentUser: null
}
}
//The code breaks here!
componentDidMount() {
auth.onAuthStateChange(user => {
this.setState({ currentUser: user });
})
}
{...}
I suppose that I need to know where the onAuthStateChange()
method lives an how to bring it to my App.js
file, but I'm not really sure that's the solution.
Upvotes: 0
Views: 935
Reputation: 598740
The method is called onAuthStateChanged
with a d
at the end. See getting the currently signed in user in the documentation.
Upvotes: 3