Firebase Custom Domain Name - firebase

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

Related

Sneaky Way Around Firebase Hosting Wildcard Subdomain for Users

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.

Mapping Custom Domains to Wildcard Sub-domains

I'm creating a NextJS project which makes use of wildcard subdomains.
I've set up wildcard subdomains on Vercel, so now each wildcard subdomain points to my main NextJS installation. Within the NextJS app, I'm reading the subdomain name and serving the content accordingly.
So, let's say my wildcard entry is *.example.com
Now, all subdomains, such as roman.example.com, greek.example.com, are being served correctly with content coming from my database correctly.
The challenge I'm facing is to map custom domains to each of these subdomains.
For example, if I want myroman.com to map to roman.example.com and mygreek.com to map to greek.example.com, I'm unable to get it to work.
Say, for example, if in myroman.com DNS records, if I add a CNAME record pointing to roman.example.com, and then if I visit myroman.com, it shows me 404 deployments not found error. Note that something like myroman.com is a customer's site, and the only thing I can ask a customer is to add a DNS record to map it to a sub-domain. I cannot take control of their domain or anything like that.
You would see that companies like substack offer such custom domain mapping to their customers.
Can you suggest what's the best way to achieve this? I'm okay to change host or anything to make this work.
Thanks to Krabs, we can host multiple websites inside of our Next.js instance and serve them separately depending on the domain that the user is browsing
https://micheleriva.github.io/krabs/docs/intro/
I hope this is what you are looking for!

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.

Making Google Oauth work locally with subdomains

I'm developing a website using ASP.NET identity that will work with subdomains that identify a client using some information from here I've got subdomains working locally, but I can't get it to work with OAuth.
For example, if I got to https://localhost:44301 and try to login with Google, everything is fine. In my Google console I have https://localhost:44301 under "Authorized JavaScript origins" and https://localhost:44301/signin-google under "Authorized redirect URIs". But when I go to https://foo.localhost:44301 Google will respond with:
Error: invalid_request
Invalid parameter value for redirect_uri: Non-public domains not allowed: https://foo.localhost:44301/signin-google
When you try to log in. I can add https://foo.localhost:44301 to "Authorized JavaScript origins" in the Google console, but it won't let me add https://foo.localhost:44301/signin-google under authorized redirect URIs because it will complain:
Invalid Redirect: https://foo.localhost:44301/signin-google must end with a public top-level domain (such as .com or .org)
Some other questions and answers suggest redirecting all subdomains to a single domain for OAuth, but ideally I want to keep logins per subdomain. So if you use google to sign it to foo.mydomain.com it will be separate from bar.mydomain.com and I don't think that'll work if I have to redirect both to the same single domain (although I'm not sure that's going to work without separate projects in Google.
Google and in general other OAuth2/OIDC providers will support redirecting to sub-domains. Your specific problem is that you seem to be trying to use sub-domains of localhost which is in the list of Special-Use Domain Names (RFC6761) and it seems Google has additional constraints for those ones.
However, this is not a real limitation because on production you'll use a public top-level domain from from where you'll have the specific sub-domains.
If you need to have this working for local development, you can use localtest.me which allows you to set a sub-domain you like (foo.localtest.me and bar.localtest.me) while still ensuring that the domain resolves to your local machine (127.0.0.1). This should stop Google from complaining about it...

Single Google Analytics for multiple domains with a single landing page?

I have a GoDadddy account with hosting and domains (I know,,, GoDaddy sucks...), but I currently have multiple domains pointing to the same folder, and it has a single PHP page with the GA tracking code for a single domain. Because all the domains point to the same folder in the hosting, I see all visits for all domains as they are for a single domain in the GA panel. Is there a way to find out which visits come from what domain?
Currently GoDaddy has 3 hosting plans. The only two that allows you to have multiple domains are Deluxe and Ultimate.
How you conduct the implementation will affect the way GA reports the data. Now I am going to make the assumption that you have access to all the domains you said you currently have.
This is what you need to do to track your traffic
Check if you are allowed to have multiple Domains.
If Domains are not registered in Godaddy, make sure that all domains and the Primary Domain are pointing to Godaddy DNS or nameservers.
Add all domains as 'addons' domains or additional domains to your hosting account making sure you have a separate folder for each domain.
In each Domain Folder, create a basic HTML (index.html) page and paste the Google Analytic code in the Head section. Repeat this for every Domain.
Create 301 redirects to your PHP page that has the same Google Analytic code that you used for all the pages in 4.
IN Google Analytics Report you should be able to see all the redirected domains show as 'referral'.
Note: Sometimes the redirect might take place before the GA script is loaded and therefore you will not be able to track the referral. If you really care about absolutely all the referral traffic data, I will recommend you to not use 301 redirect but let the pages load and place a JavaScript redirect with a 5 second delay.

Resources