0
votes

I am trying to update a Firebase document by first logging in with the admin account using Firebase Auth SDK.

  • Next I use the Firestore SDK to pull down the different parts of data needed from that plan.

  • Then push them back up to the new plan. So it’s essentially duplicating the plan.

The way I used to do it was in a self invoking function at the bottom of a HTML and just load the SDKs from their CDN.

Instructions to setup and links to CDN: https://firebase.google.com/docs/web/setup

If you try doing the

const firebaseConfig = {
    apiKey: 'api-key',
    authDomain: 'project-id.firebaseapp.com',
    projectId: 'project-id',
}

firebase.initializeApp(firebaseConfig);

var db = firebase.firestore();

db.collection("users").get().then((querySnapshot) => {
    querySnapshot.forEach((doc) => {
        // console.log(`${doc.othre} => ${doc.data()}`);
        console.log(doc);
    });
})

i get the follow error

Uncaught (in promise) FirebaseError: Missing or insufficient permissions.

1
This error message indicates a problem with your security rules. See the doc here: firebase.google.com/docs/firestore/security/overview. You may add your security rules to your question. - Renaud Tarnec
Thank you @RenaudTarnec, I know if I change the rules I can do that way, however i would like to do it the way my collegque explaind it to me. regards - Usman Sharif HH
Ok I understand. From where are you going to execute this code? As explained in the doc, "the Admin SDK lets you interact with Firebase from privileged environments" (like a server) and not from a client front-end. - Renaud Tarnec
yes that is exactly my point @RenaudTarnec thank you, how should i do that now? please help - Usman Sharif HH
If you want to use the Admin SDK from a server, please look at the doc form ore details, in particular firebase.google.com/docs/admin/setup#prerequisites. If you don't have a server, it means you will need to work out a different approach. For us to help you we need much more details on your exacts goals. - Renaud Tarnec

1 Answers

0
votes

If you want to use the Admin SDK from a server, please look at the doc for more details, in particular firebase.google.com/docs/admin/setup#prerequisites.