gpt4 book ai didi

ios - 使用 firebase-tools 删除 Firestore 文档不起作用

转载 作者:行者123 更新时间:2023-12-04 10:25:09 25 4
gpt4 key购买 nike

我正在从 iOS 调用云函数来删除 Firestore 中的文档。该函数被调用并执行,但实际删除从未发生。知道我做错了什么吗?

云函数:

const functions = require('firebase-functions');
const firebase_tools = require('firebase-tools');

exports.recursiveDelete = functions
.runWith({
timeoutSeconds: 540,
memory: '2GB'
})
.https.onCall((data, context) => {
const path = data.path;
console.log(
`User ${context.auth.uid} has requested to delete path ${path}`
);

return firebase_tools.firestore
.delete(path, {
project: process.env.GOOGLE_CLOUD_PROJECT,
recursive: true,
yes: true,
token: functions.config().fb.token
})
.then(() => {
return {
path: path
};
});
});

iOS
let deleteFunction = functions.httpsCallable("recursiveDelete")
deleteFunction.call(["path": docPath]) { (result, error) in
if let error = error as NSError? {
if error.domain == FunctionsErrorDomain {
let code = FunctionsErrorCode(rawValue: error.code)
let message = error.localizedDescription
let details = error.userInfo[FunctionsErrorDetailsKey]
print("\(code): \(message)\n\nDetails: \(details)")
}
} else {
print("Deletion was successful")
}
}

这是 Xcode 的控制台输出:
Optional(__C.FIRFunctionsErrorCode): INTERNAL

Details: nil

这是执行的日志:
enter image description here

最佳答案

尝试检查 NodeJS 的版本。在 NodeJS 10 及更高版本中,删除了许多环境变量,包括 process.env.GOOGLE_CLOUD_PROJECT ,现在返回 undefined .
而不是 process.env.GOOGLE_CLOUD_PROJECT ,您有多种选择:
将您的项目 ID 硬编码为字符串:

.delete(path, {
project: "myprojectid-12345",
recursive: true,
yes: true,
token: functions.config().fb.token
})
您还可以从 firebase 配置中获取您的项目 ID: myProjectID = JSON.parse(process.env.FIREBASE_CONFIG).projectId请注意,如前所述 here :

FIREBASE_CONFIG is always populated by the Firebase CLI whendeploying, but will not be present when deploying via gcloud or othermeans.


或基于 this documentation在部署您的函数时设置您自己的环境变量。

关于ios - 使用 firebase-tools 删除 Firestore 文档不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60654089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com