0

I was trying to implement cross-domain authentication for my domain and other sub-domains. Currently, my backend is running through firebase cloud functions. So, my backend domain is like https://my-region-firebase-project-id.cloudfunctions.net.

I was adding the cookie like this:

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

This wasn't set the cookie to my front end. Saying This attempt to set cookie via set-cookie header was blocked because its domain attribute was invalid regards to the current host url

I even tried to put a dot before the domain like this: .mydomain.com. But still the same error.

I can't add a custom domain to my firebase cloud functions, since firebase doesn't support a custom domain for other regions except us-central1.

Did I missing something or not? Or is there any workaround with it?

NB: I am able to set cookies from the cloud function, the problem is the function domain and my frontend domain is completely different.

Md Abdul Halim Rafi
  • 1,810
  • 1
  • 17
  • 25

1 Answers1

0

You can map Firebase Hosting paths to Cloud Functions!

Your Firebase Hosting site can have a custom domain connected. ex: example.com. Once done, you can update the hosting configuration in firebase.json to add custom rewrites/redirects.

"hosting": {
  // ...

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

Create a custom rewrite to one of your Firebase Functions. eg. example.com/authenticate -> myAuthenticationFunction.

See more details here: https://firebase.google.com/docs/hosting/full-config#rewrite-functions

Caine Nielsen
  • 319
  • 2
  • 14