我使用 Node 和 Express 构建了一个 Firebase HTTP 事件函数。该函数正在运行,但是当我在客户端调用该函数时,我得到403 Forbidden. 第一次调用该函数时,我被要求使用 Google 帐户登录。我使用与 Firebase 相同的帐户登录,但是当我调用该函数时,我得到了:
我查看了谷歌云平台上的use角色,调用该函数的权限设置为allUsers. 我在 Firebase CLI 中退出并重新登录。
这是index.jsfunctions文件夹中的:
const functions = require('firebase-functions');
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const port = process.env.port || 5600
const nodemailer = require('nodemailer');
app.use(express.static('Public'));
app.use(bodyParser.urlencoded({ extended: true }));
const urlencodedParser = bodyParser.urlencoded({extended: true});
app.post("/api/user", urlencodedParser, (req, res) => {
res.sendFile('../Public/bedankt.html', {root: __dirname})
const persGegevens = req.body
const string = JSON.stringify(persGegevens, …Run Code Online (Sandbox Code Playgroud) 我不知道为什么下面的代码会抛出 google api 密钥权限被拒绝的错误。我在 firebase 控制台和 google 控制台中都启用了 api 或服务。
export async function createJobDynamicLink(job){
if(job.jobStatus !== 'approved' || (job.dynamicLink).length > 2){
console.log('Dynamic link already exist!');
return false;
}
console.log(dynamic_links);
console.log(dynamic_links_key);
// Firebase web api key logs just fine
const options = {
method: 'POST',
uri: `https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=${dynamic_links_key}`,
body: {
"longDynamicLink": makeDynamicLongLink(job)
},
json: true
};
return await requestpromise(options)
.then(function (parsedBody) {
console.log(parsedBody);
return parsedBody.shortLink;
})
.then((shortLink) => {
//post.shareUrl = shortLink;
console.log('short link: ' + shortLink);
//return event.data.ref.set(post);
return shortLink;
}) …Run Code Online (Sandbox Code Playgroud) 我有一个关于 Firebase Functions V2 的问题,关于如何将 Google Secrets Manager 包含到文档触发器函数中。
我知道如何使用 OnRequest 来做到这一点,下面的工作正常。
exports.myWebhook = onRequest({secrets: [MY_WEBHOOK_SECRET, MY_TEST_SECRET_KEY]}, async (req, res) => {
const safe = STRIPE_TEST_SECRET_KEY.value();
}
Run Code Online (Sandbox Code Playgroud)
但是我似乎无法让它与 onDocumentCreated 一起使用......
exports.myUpdate = onDocumentCreated("/orders/{documentId}", async (event ) => {
const myAPIKey = MY_OTHER_API.value()
}
Run Code Online (Sandbox Code Playgroud)
每当我在此函数中的任何位置放置 {secrets: [MY_OTHER_API]} 时,都会产生错误。如果我排除它,那么 API 密钥值只是空白。
任何帮助,将不胜感激。谢谢。
尝试将 {secrets: [MY_OTHER_API_KEY]} 放入函数中以允许其访问 Google Secret 值。
javascript firebase google-cloud-functions google-cloud-firestore
使用 Firebase CLI部署 Firebase Functions 时,将对其进行配置,以便向授予Cloud Functions InvokerallUsers权限。通过这样的设置,下面的代码可以按预期运行。
还可以将Cloud Functions Invoker权限授予allAuthenticatedUsers. 但是,当我对 实施此更改时addMessage,我仅UNAUTHENTICATED使用下面的代码得到错误响应。
allAuthenticatedUsers为什么此 Firebase 云功能不起作用?
注意:此问答是由Furkan Yurdakul发布的现已删除的问题的结果,该问题涉及为什么allAuthenticatedUsers没有在他的 Firebase 应用程序中使用他的 Firebase 可调用函数
firebase.auth().signInAnonymously() // for the sake of the MWE, this will normally be Facebook, Google, etc
.then((credential) => {
// logged in successfully, call my function
const addMessage = firebase.functions().httpsCallable('addMessage');
return addMessage({ text: messageText …Run Code Online (Sandbox Code Playgroud) javascript firebase firebase-authentication google-cloud-functions
我正在阅读此 Reddit 帖子,其中一位用户提到 540 秒是 Firebase 函数的限制,建议迁移到 Cloud Run。
\n\n\n正如其他人所说,540 秒是最大超时,如果您想增加它而不更改代码的其他内容,请考虑迁移到 Cloud Run。\xe2\x80\x8b- Reddit上的@samtstern
\n
查看Node.JS 快速入门文档\n以及 YouTube 和 Google 上的其他内容后,我没有找到解释如何将 Firebase Function 移至 Cloud Run 的良好指南。
\n我读到的内容没有解决的问题之一,例如:我用什么替换firebase-functions包来定义函数?ETC...
那么,如何将我的 Firebase Function 转移到 Cloud Run 才不会遇到 540 秒的最大超时限制?
\n\xe2\x80\x8bconst functions = require(\'firebase-functions\');\n\xe2\x80\x8bconst runtimeOpts = {timeoutSeconds: 540,memory: \'2GB\'}\n\xe2\x80\x8bexports.hourlyData = functions.runWith(runtimeOpts).pubsub.schedule(\'every 1 hours\')\nRun Code Online (Sandbox Code Playgroud)\n javascript node.js firebase google-cloud-functions google-cloud-run
我有以下基于 Firebase 后端的移动应用场景:
Firebase 匿名身份验证似乎非常适合这种情况 - 但文档暗示它只能用作临时解决方案,直到用户创建实际帐户。使用匿名身份验证作为解决方案的唯一身份验证方法有什么缺点吗?我看到的替代方案是使用基于自定义令牌的登录或电子邮件/密码身份验证的某种黑客攻击。
anonymous-users firebase google-cloud-platform firebase-authentication
我想在 React Native 中执行类似以下代码的操作:
await firestore()
.collection('Users')
.doc('ABC')
.update({
this.state.documentName: url,
});
Run Code Online (Sandbox Code Playgroud)
但我需要this.state.documentName动态,但 VSCode 报告错误说':' expected.. 我缺少什么?
我是反应原生的新人。我如何清除这个useState数组?
const [tokenArray, setTokenArray]=useState([]);
// Need to Clear Array this line.
setTokenArray(tokenArray,[]);
var arraySize = responseJson.status.split(',').length;
for(var x=1;x<arraySize;x++){
console.log("X--->"+x)
setTokenArray(tokenArray => [...tokenArray, responseJson.status.split(',')[x]])
}
Run Code Online (Sandbox Code Playgroud)