//////////index.js ////////////
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
// Existing helloWorld function
exports.helloWorld = functions.https.onRequest((request, response) => {
functions.logger.info("Hello logs!", {structuredData: true});
response.send("Hello from Firebase! ::: FUNCTIONS - " + JSON.stringify(functions));
});
// New function to log newly created user's UID
exports.logNewUser = functions.auth.user().onCreate((user) => {
functions.logger.info(`New user created with UID: ${user.uid}`, {structuredData: true});
});
/////////package.json//////////////
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "18"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^12.5.0",
"firebase-functions": "^6.0.1",
},
"devDependencies": {
"firebase-functions-test": "^3.1.0"
},
"private": true
}
///////// 系统设置 ///////////
node --version
v20.17.0
npm --version
10.8.2
firebase --version
13.18.0
////////////// 错误 ////////////////
类型错误:无法读取未定义的属性(读取“用户”)
错误:无法成功分析函数代码库。它可能有语法或运行时错误
///////////// 函数信息 ///////////////
功能 - {“alerts”:{“appDistribution”:{“newTesterIosDeviceAlert”:“appDistribution.newTesterIosDevice”,“inAppFeedbackAlert”:“appDistribution.inAppFeedback”},“billing”:{“planUpdateAlert”:“billing.planUpdate”, “planAutomatedUpdateAlert”:“billing.planAutomatedUpdate”},“crashlytics”:{“newFatalIssueAlert”:“crashlytics.newFatalIssue”,“newNonfatalIssueAlert”:“crashlytics.newNonfatalIssue”,“regressionAlert”:“crashlytics.regression”,“stabilityDigestAlert”: “crashlytics.stabilityDigest”,“velocityAlert”:“crashlytics.velocity”,“newAnrIssueAlert”:“crashlytics.newAnrIssue”},“性能”:{“thresholdAlert”:“performance.threshold”},“eventType”:“google。 firebase.firebasealerts.alerts.v1.published"},"database":{"writingEventType":"google.firebase.database.ref.v1.writing","createdEventType":"google.firebase.database.ref.v1.创建了","updatedEventType":"google.firebase.database.ref.v1.updated","deletedEventType":"google.firebase.database.ref.v1.deleted"},"storage":{"archivedEvent":" google.cloud.storage.object.v1.archived","finalizedEvent":"google.cloud.storage.object.v1.finalized","deletedEvent":"google.cloud.storage.object.v1.deleted"," metadataUpdatedEvent":"google.cloud.storage.object.v1.metadataUpdated"},"https":{},"identity":{},"pubsub":{},"logger":{},"tasks": {},"eventarc":{},"scheduler":{},"remoteConfig":{"eventType":"google.firebase.remoteconfig.remoteConfig.v1.updated"},"testLab":{"eventType": "google.firebase.testlab.testMatrix.v1.completed"},"firestore":{"writingEventType":"google.cloud.firestore.document.v1.writing","createdEventType":"google.cloud.firestore.document .v1.created","updatedEventType":"google.cloud.firestore.document.v1.updated","deletedEventType":"google.cloud.firestore.document.v1.deleted","writingEventWithAuthContextType":"google.cloud .firestore.document.v1.writing.withAuthContext","createdEventWithAuthContextType":"google.cloud.firestore.document.v1.created.withAuthContext","updatedEventWithAuthContextType":"google.cloud.firestore.document.v1.updated.withAuthContext ","deletedEventWithAuthContextType":"google.cloud.firestore.document.v1.deleted.withAuthContext"},"params":{"BUCKET_PICKER":{"resource":{"type":"storage.googleapis.com/Bucket "}},"declaredParams":[],"databaseURL":"params.DATABASE_URL","projectID":"params.PROJECT_ID","gcloudProject":"params.GCLOUD_PROJECT","storageBucket":"params.STORAGE_BUCKET" },"应用程序":{}}
为什么
auth
在functions.auth.user()
中未定义?
我已经尝试卸载并重新安装
npm
、node 和 Firebase cli
。我期待着功能的部署。
我有同样的问题,我通过谷歌发现了这个: 发现这个:https://github.com/firebase/firebase-functions/issues/1622