Hey there, I'm trying to retrieve data from Firestore within a cloud function. To initialize Firebase, I have a file called firebase.ts:
import * as admin from "firebase-admin";
import { getFirestore } from "firebase-admin/firestore";
import * as functions from "firebase-functions";
import { initializeApp } from "firebase/app";
admin.initializeApp({
credential: admin.credential.cert({
privateKey: functions.config().private.key.replace(/\\n/g, "\n"),
projectId: functions.config().project.id,
clientEmail: functions.config().client.email,
}),
databaseURL: `https://${functions.config().project.id}.firebaseio.com`,
});
const app = initializeApp({
appId:functions.config().app.id
})
const db = getFirestore();
const realtime = admin.database();
export {admin, db, realtime};
Then, in my index.ts file, I use the following:
const ref = doc(db, "users", uid);
The issue I'm encountering is that Visual Studio Code is giving me an error for 'db' inside 'doc':
No overload matches this calls. Argument of type 'Firestore' is not assignable to parameter of type 'DocumentReference<unknown, DocumentData>'. Type 'Firestore' is missing the following properties from type 'DocumentReference<unknown, DocumentData>': converter, type, firestore, id, and 3 more.
I have followed the official documentation at https://firebase.google.com/docs/firestore/query-data/get-data and https://blog.logrocket.com/building-rest-api-firebase-cloud-functions-typescript-firestore/, but nothing seems to work. It could be a configuration problem, but I'm not sure. Appreciate any help. Thank you.