Ошибка при отправке данных в Firestore
Имеется данный хендле на форме:
import { useState } from 'react'
import { collection, addDoc } from "firebase/firestore";
import db from '../../firebase'
const [productName, setProductName] = useState()
const [productCode, setProductCode] = useState()
const [productManufacturing, setProductManufacturing] = useState()
const [productShelfLife, setProductShelfLife] = useState()
const [productQuantity, setProductQuantity] = useState()
const handlerSubmit = async (e) => {
e.preventDefault();
try {
const docRef = await addDoc(collection(db, "products"), {
name: productName,
code: productCode,
quantity: productQuantity,
date_1: productManufacturing,
date_2: productShelfLife
});
console.log("Document written with ID: ", docRef.id);
} catch (e) {
console.error("Error adding document: ", e);
}
}
Firebase config:
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
import { getFirestore } from "firebase/firestore";
const firebaseConfig = {
apiKey: process.env.REACT_APP_FIREBASE_KEY,
authDomain: process.env.REACT_APP_FIREBASE_DOMAIN,
databaseURL: process.env.REACT_APP_FIREBASE_DATABASE_URL,
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
storageBucket: process.env.REACT_APP_FIREBASE_BUCKET,
messagingSenderId: process.env.REACT_APP_FIREBASE_SENDER_ID,
appId: process.env.REACT_APP_FIREBASE_APP_ID
};
const app = initializeApp(firebaseConfig);
export const auth = getAuth(app);
export const db = getFirestore(app)
export default app
При отправке получаю ошибку: "Error adding document: FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore"
может кто знает что делаю не так?