admin管理员组文章数量:1389762
I have a Firebase function called onUserStatusChanged
that mirrors real-time data from the Firebase Realtime Database
to Firestore
like following :
(By the way, I copied this code from Google)
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const firestore = admin.firestore();
exports.onUserStatusChanged = functions
.region("europe-west1").
database.ref("/users/{uid}").onUpdate(
async (change, context) => {
// Get the data written to Realtime Database
const eventStatus = change.after.val();
// Then use other event data to create a reference to the
// corresponding Firestore document.
const userStatusFirestoreRef = firestore.
doc(`users/${context.params.uid}`);
// It is likely that the Realtime Database change that triggered
// this event has already been overwritten by a fast change in
// online / offline status, so we'll re-read the current data
// and compare the timestamps.
const statusSnapshot = await change.after.ref.once("value");
const status = statusSnapshot.val();
functions.logger.log(status, eventStatus);
// If the current timestamp for this data is newer than
// the data that triggered this event, we exit this function.
if (status.lastChanged > eventStatus.lastChanged) {
return null;
}
// Otherwise, we convert the last_changed field to a Date
eventStatus.lastChanged = new Date(eventStatus.lastChanged);
// ... and write it to Firestore.
return userStatusFirestoreRef.update(eventStatus);
});
This code was working correctly for a year, but it suddenly stopped working after I integrated the BigQuery extension into Firebase, if I'm not mistaken or if it’s not just a coincidence.
the errors logs :
onUserStatusChangedoplb4jqmbm76 Error: 7 PERMISSION_DENIED: Missing or insufficient permissions.
at callErrorFromStatus (/workspace/node_modules/@grpc/grpc-js/build/src/call.js:31:19)
at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client.js:192:76)
at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:360:141)
at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:181)
at /workspace/node_modules/@grpc/grpc-js/build/src/resolving-call.js:94:78
at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
Firestore rules:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write;
}
}
}
Realtime Database rules:
{
"rules": {
".read": true,
".write": true,
}
}
The following is what currently exists in my Google Cloud / service accounts:
Google Cloud Service Accounts for myApp-68ccf
App Engine Default Service Account
Email: [email protected]
Status: Enabled
Keys: No keys
Default Compute Service Account
Email: [email protected]
Status: Enabled
Keys: No keys
Firestore BigQuery Export Service Account
Email: ext-firestore-bigquery-export@myApp--68ccf.iam.gserviceaccount
Status: Enabled
Keys: No keys
Firestore BigQuery Export (Alternate) Service Account
Email: ext-firestore-bigquery-ex-p6tr@myApp--68ccf.iam.gserviceaccount
Status: Enabled
Keys: No keys
Firebase Admin SDK Service Account
Email: [email protected]
Status: Enabled
Keys:
Key ID: cedfssdfsfsdfsbsndksandlkanfklanalnlk765 (Created: Sep 23, 2024)
Key ID: alkdlklknlkdjfkjdjzkmdlakjffoihkjaiowjwo (Created: Sep 23, 2024)
Key ID: faklkdlmfoijoiewjpojeoqjepowjepoajdajwwp5 (Created: Mar 13, 2025)
The following is what currently exists in my Google Cloud / IAM / Permissions for project:
Google Cloud IAM Roles for myApp
1. Default Compute Service Account
Email: [email protected]
Type: Default Compute Service Account
Roles:
Editor
2. Firestore BigQuery Export (Alternate) Service Account
Email: [email protected]
Type: Firebase Extensions Firestore BigQuery Export-r7pi Service Account
Roles:
BigQuery Data Editor
BigQuery User
Cloud Datastore User
3. Firestore BigQuery Export Service Account
Email: [email protected]
Type: Firebase Extensions Firestore BigQuery Export Service Account
Roles:
BigQuery Data Editor
BigQuery User
Cloud Datastore User
4. Firebase Admin SDK Service Account
Email: [email protected]
Type: Firebase Admin SDK
Roles:
Cloud Functions Admin
Editor
Firebase Admin
Firebase Admin SDK Administrator Service Agent
Firebase Authentication Admin
Firebase Realtime Database Admin
Firestore Database Reliability Recommender Admin
Firestore Service Agent
Service Account Token Creator
Storage Admin
5. Firebase Service Management Service Agent
Email: firebase-service-account@firebase-sa-management.iam.gserviceaccount
Type: Firebase Service Management Service Agent
Roles: (Not specified)
6. Personal Account - Owner
Email: [email protected]
Name: Mohammed Hamdan
Role: Owner
7. BigQuery & Firebase Admin Account
Email: [email protected]?uid=117641135490648667432
Roles:
BigQuery Admin
Firebase Admin
8. App Engine Default Service Account
Email: [email protected]
Type: App Engine Default Service Account
Roles: (Not specified)
I can write to Firestore and the database in real time normally from my app. I can also authenticate normally and other functions in Firebase are working correctly, but not the one mentioned in my question
本文标签: nodejsPERMISSIONDENIED Missing or insufficient permissionsFirebase functionStack Overflow
版权声明:本文标题:node.js - PERMISSION_DENIED: Missing or insufficient permissions - Firebase function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744700804a2620551.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论