Sneaky Way Around Firebase Hosting Wildcard Subdomain for Users - firebase

I want to let users sign-up for a sub-domain on my app's main domain. Unfortunately Firebase Hosting doesn't support wildcard subdomains (yet?), but I think I have an almost-automated way to do this.
I'll lay out my plan, but I'd really appreciate any feedback or improvements of how else I should solve this problem.
Steps:
Gather a user's intention to create a subdomain
Automate Firebase CLI to create another site, get DNS settings and add them into a Firestore doc (that I will then show the user)
Upload a simple HTML page with <object> and their site app.website/username
Cry because <objects> doesn't change the URL in the browser
Each user has a public profile on the main domain, like this: app.website/username, but I want to also host this page at username.app.website so they can point their domain (or subdomain) to their app.
Is there a way to do this efficiently?

From the documentation on connecting to Firebase Hosting:
Each custom domain is limited to having 20 subdomains per apex domain, due to SSL certificate minting limits.
So you can't have more than 20 subdomains. As long as you stay within that limit, you approach could work. But it won't allow you to go over the limit.

Related

How to stay logged in cross domain firebase?

I'm developing my project and here is a deal: I'm having firebase auth email and password based. Then I've created landing for users and what I'm trying is to let users signup from landing which is on different domain and stayed logged in on my main app.
I've looked up firebase docs but didn't find any snippets. Basically I think there should be auth provider config, but again there is no info. Maybe you've faced such an issue, how you've solved it?
You cannot signup users on one domain and allow them to login into a different domain with those signup credentials. Firebase doesn't allow that. Each domain has its own auth setup that doesn't coincide with another domain's authentication. You can use sub domains if you want. ->
https://dev.to/johncarroll/how-to-share-firebase-authentication-across-subdomains-1ka8
You will have to create cloud functions but to achieve this even on subdomains.
Gist of that article.
Getting Firebase Authentication to work across subdomains is not super
straightforward, but it is doable without that much work.
Unfortunately, you need to be familiar with a number of concepts such
as CORS, cookies, JWTs, Firebase Authentication itself, etc.
Might as well develop your own Nodejs server instead of using hacks and workarounds like in the article.

concerns about required A records for setting up Firebase Dynamic Links with a custom subdomain

In setting up our own subdomain to handle Firebase Dynamic Links using these docs, the wizard says to put the A records at example.com in our DNS. I'm getting pushback from our network administrators who are wary of creating an A record at the root of our domain, which is a large e-commerce web site.
A couple of concerns/questions about this:
The IP addresses required (151.101.1.195 and 151.101.65.195) point to non-Google servers (looks like Fastly), which is a bit alarming - it seems strange that Google would outsource their deep link hosting.
We don't want all of our e-commerce traffic (coming through example.com) to be subject to these A records. Is it possible to put the A records at link.example.com instead?
The Firebase documentation on using a custom domain for dynamic links has this note:
To use a custom domain for Dynamic Links, the domain must point to Firebase Hosting. If you have a domain you want to use with Dynamic Links and the domain points to a different host, you can either move to Firebase Hosting or create a subdomain hosted by Firebase, which you can use for Dynamic Links.
So you can indeed use a subdomain for the dynamic links. In that case, just set up the subdomain in Firebase hosting. You'll need the same TXT record as normal, to prove that you have access to the domain, but then just map the subdomain (e.g. links) for the A record.
Here is the answer I received from Firebase support about these my two concerns/questions:
Regarding Fastly, Firebase uses this subprocessor to deliver content and managed services on Firebase Hosting. For more details you could check the list of Subprocessors used by Firebase on this doc.
It's possible to use a subdomain as your Firebase project's FDL domain. You'd need to create a subdomain (link.example.com) on your domain's DNS provider and connect it to Firebase Hosting. You could check out this guide for more details.

How to redirect logged in user to subdomain using Firebase Auth and Hosting?

My primary domain is domain.com that I plan to use as a landing page. I have a subdomain of app.domain.com for the actual webapp site. My desired outcome is as follows:
Not Logged In: domain.com -> domain.com/login -> app.domain.com
Logged In: redirected to app.domain.com
Is this possible with Firebase Hosting? I see now Firebase allows different sites in the same project. Would I use this to create two different sites and just redirect on the client side? That's the only way I see can work while keeping the auth state across the app. Is there a better way to do this, as it seems to be pretty a common use case?
Do you have a need for authentication on the root domain at all?
If not, you can place the login page on the subdomain and not add the complexity of authentication across two domains.

Firebase Custom Domain Name

I’m having a lot of trouble configuring my custom domain. Currently, if you go to my site www.mydomain.com it redirects to the default somecrazyname.firebase.com. In my google domains, I just have both www.mydomain.com and mydomain.com redirecting to the mycrazyname.firebase.com just for the sake of having something live until I can figure this out. My question is, how do I make it so when you go to www.mydomain.com it stays on www.mydomain.com while showing my amazing content and not somecrazyname.firebase.com.
Everything is configured correctly with firebase as far as my custom url goes(verification, etc.). However, the url firebase gave me is https mydomain.com (where if you go there it says the site can't be displayed) where my domain on Google domains is http. I've tried to configure redirects within my firebase json as well as my synthetic records in Google domains, but have had no such luck and am out of ideas. I've also looked at the firebase hosting custom domains documentation and am just not getting it.
Here are some visuals....
My redirects as seen on Google domains
I'm sure it's just a matter of putting things in the right places, but I have been trying this for a few hours and have not had any luck.
It was the synthetic records that was causing the issue for me. I was using CName records which, by the direction of the firebase support team is good only for subdomain redirects. Below is part of an email from the firebase support team. This is her answer to this as well as some helpful explanations.
Firebase uses TXT records for the verification of your custom domain.
On the other hand, CNAME and/or A records are used for redirection. Please take note of the following:
If you have a subdomain, CNAME records are recommended
Note that the host name with "*" indicates a wildcard. Any subdomains typed before your custom domain will redirect you to your
hosted custom domain.
Otherwise, if you have a custom domain without a subdomain, A records are recommended.
Note that adding both A records will increase redirection performance
Also, kindly remove other A records that are not from Firebase to prevent redirection issues
That's about it. Firebase Static Hosting only needs three records
(TXT, CNAME, A). Other than that, you wouldn't have the need to
implement domain forwarding such as your Synthetic records. Moving
forward though, I would suggest you to remove your Synthetic records
and add the A records I have provided on my previous email.
You should NOT be using a redirect (301 or 302) record for your domain. Instead, you should set a CNAME record. Here's how to fix it:
Delete the second redirect in your screenshot (the one that redirects to Firebase).
Go to the DNS tab of your Google Domains control panel, scroll down to the Custom resource records section, and add a record that looks like this:
www | CNAME | _____ | portfolio-6f15b.firebaseapp.com

How to authenticate only once with http auth and two domains in nginx?

I have a site that requires 2 domains: one for dynamic and the other for static content.
In the staging environment I need it to ask for user and password as I don't want random people or bots having access to that. I have used http_auth for that.
The problem is that when you try to access, it asks for your credentials twice: once for each domain. Which is annoying.
How can I avoid that?

Resources