小编sam*_*man的帖子

Firebase 函数 HTTPS 403 禁止

我使用 Node 和 Express 构建了一个 Firebase HTTP 事件函数。该函数正在运行,但是当我在客户端调用该函数时,我得到403 Forbidden. 第一次调用该函数时,我被要求使用 Google 帐户登录。我使用与 Firebase 相同的帐户登录,但是当我调用该函数时,我得到了:

403错误截图

我查看了谷歌云平台上的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)

node.js express firebase google-cloud-functions

13
推荐指数
3
解决办法
9042
查看次数

Firebase Cloud Functions:来自引用者 <empty> 的请求被阻止。- 没有权限

我不知道为什么下面的代码会抛出 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)

node.js firebase firebase-dynamic-links request-promise

7
推荐指数
2
解决办法
8656
查看次数

Firebase 函数 V2 文档触发器中的 Google 秘密

我有一个关于 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

7
推荐指数
1
解决办法
844
查看次数

为什么我的 Firebase Cloud Function 无法使用“allAuthenticatedUsers”?

使用 Firebase CLI部署 Firebase Functions 时,将对其进行配置,以便向授予Cloud Functions InvokerallUsers权限。通过这样的设置,下面的代码可以按预期运行。

还可以将Cloud Functions Invoker权限授予allAuthenticatedUsers. 但是,当我对 实施此更改时addMessage,我仅UNAUTHENTICATED使用下面的代码得到错误响应。

allAuthenticatedUsers为什么此 Firebase 云功能不起作用?


注意:此问答是由Furkan Yurdakul发布的现已删除的问题的结果,该问题涉及为什么allAuthenticatedUsers没有在他的 Firebase 应用程序中使用他的 Firebase 可调用函数


MWE 基于文档addMessage定义如下

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

5
推荐指数
1
解决办法
1681
查看次数

遇到 540 秒超时限制后如何从 Firebase Functions 迁移到 Cloud Run?

我正在阅读此 Reddit 帖子,其中一位用户提到 540 秒是 Firebase 函数的限制,建议迁移到 Cloud Run。

\n
\n

正如其他人所说,540 秒是最大超时,如果您想增加它而不更改代码的其他内容,请考虑迁移到 Cloud Run。\xe2\x80\x8b- Reddit上的@samtstern

\n
\n

查看Node.JS 快速入门文档\n以及 YouTube 和 Google 上的其他内容后,我没有找到解释如何将 Firebase Function 移至 Cloud Run 的良好指南。

\n

我读到的内容没有解决的问题之一,例如:我用什么替换firebase-functions包来定义函数?ETC...

\n

那么,如何将我的 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\')\n
Run Code Online (Sandbox Code Playgroud)\n

javascript node.js firebase google-cloud-functions google-cloud-run

3
推荐指数
1
解决办法
2013
查看次数

使用 Firebase 匿名身份验证作为应用程序中的唯一身份验证方法

我有以下基于 Firebase 后端的移动应用场景:

  • 两个或多个移动应用程序实例通过中央服务(可信)相互通信。这些应用程序通过交换共享密钥进行配对,例如通过扫描二维码或输入配对码。
  • 用户是匿名的,即不需要(或可能)注册。本质上,它是特定设备上的特定应用程序与同上的对应应用程序(相对于用户到用户)配对。
  • 交换的信息是敏感的,但没有内在价值:必须可以相信信息来自给定设备,并且必须可以相信信息已到达预期设备而不是冒充设备。但应用程序实例的信息丢失并不是关键问题,例如,如果应用程序被删除或设备被破坏(需要重新配对的烦恼,但不是关键问题)。

Firebase 匿名身份验证似乎非常适合这种情况 - 但文档暗示它只能用作临时解决方案,直到用户创建实际帐户。使用匿名身份验证作为解决方案的唯一身份验证方法有什么缺点吗?我看到的替代方案是使用基于自定义令牌的登录或电子邮件/密码身份验证的某种黑客攻击。

anonymous-users firebase google-cloud-platform firebase-authentication

3
推荐指数
1
解决办法
673
查看次数

如何更新 Firebase Firestore 中的动态字段名称?

我想在 React Native 中执行类似以下代码的操作:

await firestore()
      .collection('Users')
      .doc('ABC')
      .update({
        this.state.documentName: url,
      });
Run Code Online (Sandbox Code Playgroud)

但我需要this.state.documentName动态,但 VSCode 报告错误说':' expected.. 我缺少什么?

TypeScript 注释的图像

javascript firebase reactjs react-native

2
推荐指数
1
解决办法
795
查看次数

如何从 useState 中清除数组

我是反应原生的新人。我如何清除这个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)

reactjs react-native

1
推荐指数
1
解决办法
8977
查看次数