I started to get this error after editing my react.js code and i couldnt get rid of it. Checked some other pages about firebase.auth is not a function error but the answers there didnt help. Error gives at the beginninh of main.js file starting with "fire.auth..."
Exact error message:
TypeError: _config_Fire__WEBPACK_IMPORTED_MODULE_2__.default.auth(...).collection is not a function
My fire.js code
import firebase from 'firebase';
import 'firebase/firestore'
const config = { /* COPY THE ACTUAL CONFIG FROM FIREBASE CONSOLE */
my config info here ...
};
const fire = firebase.initializeApp(config);
export default fire;
My main.js file which gives error:
import React, {useState,useEffect, useRef, useContext} from 'react'
import fire from '../config/Fire';
//import { UserConsumer } from './UserContext.js';
//import {UserContext} from '../App'
function useTimes(){
//const user2 = useContext(UserContext.Consumer)
const [kullanici,setTimes] = useState([])
useEffect(()=>{
fire
.auth()
.collection('kullanici')
.doc('gNfFy0uEsk5OvrZOfkGm')
.onSnapshot((doc)=>{
const newTimes = doc.data()
setTimes(newTimes)
})
},[])
return kullanici
}
function useInterval(callback, delay) {
const savedCallback = useRef();
// Remember the latest callback.
useEffect(() => {
savedCallback.current = callback;
}, [callback]);
// Set up the interval.
useEffect(() => {
function tick() {
savedCallback.current();
}
if (delay !== null) {
let id = setInterval(tick, delay);
return () => clearInterval(id);
}
}, [delay]);
}
const Main = () => {
//console.log(firebase.auth().currentUser.uid)
const kullanici =useTimes()
let [count, setCount] = useState(0);
//console.log(new Date().getTime())
useInterval(() => {
// Your custom logic here
setCount(count + 1);
}, 1000);
return(
<div>
<div>
<h2>Welcome {kullanici.nick}</h2>
<li>Silver: <span>{kullanici.silver ? count * kullanici.silver : ''}</span></li>
<li>Copper: <span id="count">{kullanici.silver ? count * kullanici.copper : ''}</span></li>
<li>Iron: <span id="count">{kullanici.silver ? count * kullanici.iron : ''}</span></li>
</div>
</div>
)
}
export default Main