Reputation: 15
I created login code for my website using reactjs. when I edit the codes and run the program, it will be an error.
heres an error enter image description here
I am already uploaded the code on codesandbox the link for the code
Upvotes: 0
Views: 1442
Reputation: 26296
In the future, please include a minimal working example of your code and what the error is in your question.
That said, the reason you are getting ...default.auth is not a function
is because the default export of ./firebase/firebase.js
is a firebase.database.Reference
, not the general firebase
namespace you were expecting.
export default fireDb.database().ref(); // A firebase.database.Reference
However as you named the variable fireDb
, it is implied that it is an instance of Firebase Database, not a reference. I recommend renaming your variables to reflect this.
The file ./firebase/firebase.js
:
import firebase from 'firebase/app'
import 'firebase/database'
const firebaseConfig = { ... };
// Initialize Firebase
const fireApp = firebase.initializeApp(firebaseConfig);
export default fireApp.database();
Then, to get an instance of firebase.auth.Auth
from a firebase.database.Database
, you would use fireDb.app.auth()
.
The file ./App.js
:
import fireDb from "./firebase/firebase";
/* ... */
const handleLogout = () => {
fireDb.app.auth().signOut();
};
Upvotes: 3