【问题标题】:How to set cookie to frontend with cross domain from firebase cloud http functions?如何通过firebase云http功能将cookie设置为跨域前端?
【发布时间】:2021-09-30 01:21:25
【问题描述】:

我试图为我的域和其他子域实现跨域身份验证。目前,我的后端正在通过 firebase 云功能运行。所以,我的后端域就像https://my-region-firebase-project-id.cloudfunctions.net。

我是这样添加 cookie 的:

res.cookie("foo", "bar", {
    domain: "mydomain.com",
    path: "/",
    httpOnly: false,
    maxAge: 1209600000,
    sameSite: "None",
    secure: true
});

这不是我的前端设置的 cookie。说 这种通过 set-cookie 标头设置 cookie 的尝试被阻止了,因为它的域属性对于当前主机 url 无效

我什至尝试在域前添加一个点,如下所示:.mydomain.com。但还是同样的错误。

我无法将自定义域添加到我的 firebase 云功能,因为除了 us-central1 之外,firebase 不支持其他区域的自定义域。

我是否遗漏了什么?或者有什么解决办法吗?

注意:我可以从云端功能设置cookies,问题是功能域和我的前端域完全不同。

【问题讨论】:

    标签: node.js firebase express google-cloud-functions session-cookies


    【解决方案1】:

    您可以将 Firebase 托管路径映射到 Cloud Functions!

    您的 Firebase 托管站点可以连接自定义域。例如:example.com。完成后,您可以更新 firebase.json 中的托管配置以添加自定义重写/重定向。

    "hosting": {
      // ...
    
      // Directs all requests from the page `/bigben` to execute the `bigben` function
      "rewrites": [ {
        "source": "/bigben",
        "function": "bigben"
      } ]
    }
    

    为您的 Firebase 函数之一创建自定义重写。例如。 example.com/authenticate -> myAuthenticationFunction.

    在此处查看更多详细信息: https://firebase.google.com/docs/hosting/full-config#rewrite-functions

    【讨论】:

      猜你喜欢
      • 2021-12-07
      • 2021-04-22
      • 2015-03-29
      • 1970-01-01
      • 2018-06-30
      • 2017-06-09
      • 2020-11-10
      • 2019-03-24
      • 1970-01-01
      相关资源
      最近更新 更多