公众无法访问 Firebase Cloud Function [应用程序正在请求访问您的 Google 帐户的权限。]

标签 firebase google-cloud-functions

我刚刚将 Express 与 Firebase Cloud Functions 一起使用并创建了一个端点。

app.get('/time', (req, res) => {
    const date = new Date();
    const hours = (date.getHours() % 12) + 1;  // London is UTC + 1hr;
    res.json({bongs: 'BONG '.repeat(hours)});
});
端点可通过以下路径公开访问:
https://<region>-<project-name>.cloudfunctions.net/app/time
其中 app 来自入口源 index.js:
exports.app = functions.region('asia-east2').https.onRequest(app);
但是,它不能通过以下路径访问:
https://<project-name>.web.app/app/time
它要求我授予权限并默认选择我的 Google 帐户。怎么会?端点用于公共(public)访问。
我是否错过了任何设置以及如何解决此问题?
enter image description here
如果我不使用 Express Framework,则上述 2 条路径都可供公众访问。 (即从您的应用调用函数,https://firebase.google.com/docs/functions/callable)
谢谢~

最佳答案

无法访问的路径意味着您正在尝试使用 Firebase 托管访问 Cloud Functions。当访问您的函数时出现问题时会出现该错误。只是为了给你一个想法,这里有一个类似错误的线程:
firebase SSR problem, "App requesting permission to access your google account" pops up instead of website

Imporant Note: Before going to the solution, you must know that Firebase Hosting currently supports Cloud Functions that are in us-central1. You can't use any other regions for your function such as asia-east2.


展望 future ,您需要在托管部分设置重写规则,以服务于您在 Express 应用程序上配置的子路径:
firebase.json :
"hosting": {
  "public": "public",
  "ignore": [
    "firebase.json",
    "**/.*",
    "**/node_modules/**"
  ],  
  "rewrites": [ {
    "source": "/time",
    "function": "app"
  } ]
}
如果您正确执行此操作,您应该能够通过此路径访问您的函数:
https://<project-name>.web.app/time

Note that the path in Firebase Hosting is /time, not /app/time.



引用:https://firebase.google.com/docs/hosting/functions#use_a_web_framework

关于公众无法访问 Firebase Cloud Function [应用程序正在请求访问您的 Google 帐户的权限。],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66499168/

相关文章:

google-cloud-functions - Google Cloud 功能向 GKE 上托管的应用发送调用

javascript - Firebase 添加内部 for 循环

firebase - 将数据从 FirebaseListObservable 提取到数组

angular - 在 firebase 云函数中部署 nestjs

firebase - CLI 问题 : "The following functions are found in your project but do not exist in your local source code" - how to default answer No?

firebase - 如何在忽略现有功能的同时部署 Cloud Functions?

ios - 获取文件上传者的UID

geocoding - 在 Firebase 中处理地理编码?

ios - 向下滚动和向上滚动后 UITableViewCell 中的图像发生变化

node.js - 使用云函数时限制对第三方API的请求