简体   繁体   中英

Why does my service account not give remote access to Google Cloud Firestore?

So I followed the instructions here: https://firebase.google.com/docs/firestore/quickstart to get my Node app working with Firestore (under Initialize on your own server ). I created a service account like they say, giving it the the "Cloud Firestore Editor" privilege and downloaded the .json key file. When I run the example code like so though:

 const admin = require('firebase-admin'); const serviceAccount = require('./gcloud-service-account.json') admin.initializeApp({ credential: admin.credential.cert(serviceAccount) }); var db = admin.firestore(); db.settings({ timestampsInSnapshots: true }) var docRef = db.collection('users').doc('alovelace'); var setAda = docRef.set({ first: 'Ada', last: 'Lovelace', born: 1815 }); 

I get this error:

UnhandledPromiseRejectionWarning: Error: 7 PERMISSION_DENIED: Missing or insufficient permissions.

What am I doing wrong, or what steps could I take to debug this? Thanks!

Never mind.... It was the last step of service account creation I was missing - you have to grant user access to itself for some reason, so put the newly created account name in the "grant users" box. Hope that helps someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM