I get the error message ‘FirebaseError: Missing or insufficient permissions.’
I get this error only when I try to access second firestore(‘db2’), No problem when accessing ‘db1’
In firebase.js:
import firebase from "firebase/compat/app";
import "firebase/compat/auth";
import "firebase/compat/firestore";
const firebaseConfig = {
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
};
const firebaseConfig2 = {
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: "",
};
const firebaseApp1 = firebase.initializeApp(firebaseConfig);
const firebaseApp2 = firebase.initializeApp(firebaseConfig2, "app2");
const db1 = firebaseApp1.firestore();
const db2 = firebaseApp2.firestore();
const auth1 = firebase.auth(firebaseApp1);
const auth2 = firebase.auth(firebaseApp2);
export { db1, auth1, db2, auth2 };
Code that I access ‘db2’ in a page:
import { db1, db2 } from "./firebase"
const getStudents = async () => {
const colRef = collection(db2, 'students')
const q = query(colRef)
const querySnapshot = await getDocs(q)
...
}