I can’t write to firestore. It’s working for Storage and Realtime Database, but not for firestore, can you suggest where the issue might be?
firebase.js
import { getFirestore } from "firebase/firestore";
const firebaseConfig = {
...
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
export const firestore = getFirestore(app);
CheckoutForm.js
import { collection, addDoc } from "firebase/firestore";
import { firestore } from "../../firebase";
export const CheckoutForm = async (uid) => {
console.log("object 1")
try {
const docRef = await addDoc(collection(firestore, "documents"), {
first: "Ada",
last: "Lovelace",
born: 1815
});
console.log("Document written with ID: ", docRef.id);
} catch (e) {
console.error("Error adding document: ", e);
}
console.log("object 2")
}
Here I call CheckoutForm.
Home.js
import { loadStripe } from "@stripe/stripe-js";
import { Elements } from "@stripe/react-stripe-js"
const PUBLIC_KEY = "pkey_test_stripe"
const stripeTestPromise = loadStripe(PUBLIC_KEY);
export default function Home() {
return (
<Elements stripe={stripeTestPromise}>
<div>
<button onClick={() => CheckoutForm(currUser.uid)}>
Upgrade to premium!
</button>
</div>
</Elements>
);
}
For some reason I don’t get any response or error. Console written "object1", but after try/catch construction nothing runs.
2
Answers
I have found the root of problem, there was title directly in firestore "Databases linking, you should unlink if you want use this", some king of that. So I have clicked and after all works.