Below is my working GET API, however it is using admin.firestore.
As I am a new programmer, I am having difficulties incorporating the Authentication portion
app.get("/", async (req, res) => {
const snapshot = await admin.firestore().collection("users").get();
let user = [{records:[]}];
snapshot.forEach((doc) => {
let id = doc.id;
let data = doc.data();
users.records.push({ id, ...data });
});
res.status(200).send(JSON.stringify(users));
});
What I hope to achieve is that users can only access their own database hopefully something like this
app.get("/", async (req, res) => {
const snapshot = await [user uid's reference].collection([grab user's uid and insert here]).get();
let [insert user's uid here] = [{records:[]}];
snapshot.forEach((doc) => {
let id = doc.id;
let data = doc.data();
[insert user's uid here].records.push({ id, ...data });
});
res.status(200).send(JSON.stringify([insert user's uid here]));
});