47

I am busy setting up a firebase authentication using an email magic link and using the guide here:

https://firebase.google.com/docs/auth/android/email-link-auth

It says I need to whitelist a domain, but I cannot find any place in the console to do that, other than the dynamic link I created. I tried running the below code, but I get

[ UNAUTHORIZED_DOMAIN:Domain not whitelisted by project ]

    val actionCodeSettings = ActionCodeSettings.newBuilder()
            // URL you want to redirect back to. The domain (www.example.com) for this
            // URL must be whitelisted in the Firebase Console.
            .setUrl("https://myapphere.page.link/register") //I created this dynamic link in the firebase console
            .setHandleCodeInApp(true)
            .setAndroidPackageName(
                    "com.myapphere",
                    true, 
                    "1")
            .build()

    val auth = FirebaseAuth.getInstance()
    auth.sendSignInLinkToEmail(email, actionCodeSettings)
            .addOnCompleteListener(this) { task ->
                if (task.isSuccessful) {
                    // Sign in success, update UI with the signed-in user's information
                } else {
                    // If sign in fails, display a message to the user.
                }
            }

Am I not supposed to use dynamic links for firebase authentication? And if so, where in the console do I whitelist domains, because I cannot find it.

Jacques.S
  • 3,262
  • 2
  • 21
  • 27
  • In my case, the problem was a result of not setting up all the Firebase Dynamic Links. This new video tutorial from the Firebase team "Getting started with email/link auth on iOS" goes through the entire process: https://youtu.be/-OK7VG7Cl8I – Brad Grissom Jul 20 '23 at 18:50

5 Answers5

77
  1. Go to Firebase Console
  2. Click Authentication Menu > Sign-in method tab
  3. Scroll Down to Authorized domains
  4. Click "Add domain" button, add your domain (website domain with parameter) and click "Add"

Scroll further down on this page

Jacques.S
  • 3,262
  • 2
  • 21
  • 27
  • 15
    Maybe you can explain a little bit more what "domain" means. It can be app domain like com.yourcompany.yourappname or website domain like yourcompanyappname.com. To newer developers that information might be useful. In your case it might be myapphere.page.link on setUrl, but it's good to mention that. – Marcos Rocha Jan 06 '20 at 19:10
  • 1
    Can i then use com.yourcompany.yourappname as domain name under Authorized domains? – Brendan Aug 23 '20 at 02:16
  • 1
    the domain I am using is authorized an it's still not working – Jeff Voss Jan 24 '22 at 01:39
  • My solution was a stupid mistake. I was using an environment variable to set the ActionCodeSettings url param to the wrong domain. – Matthew Rideout Jul 30 '22 at 23:15
  • Note: The location of the list of "Authorized domains" has been moved to `Authentication->Settings` – Silvan Mühlemann Mar 03 '23 at 16:59
7

Go to https://console.firebase.google.com/project/<project-id>/authentication/settings

Click on "Authorized domains"

Click on "Add domain"

enter image description here

Julien Reszka
  • 888
  • 12
  • 25
2

I had the same problem, the reason was my SHA-1 key configured in Firebase was wrong.

Jack'
  • 1,722
  • 1
  • 19
  • 27
2

More details: This issue happen when I tried to sendSignInLinkToEmail like this

firebase
  .auth()
  .sendSignInLinkToEmail('someone@example.com', {
    url: 'my.custom.domain',
    handleCodeInApp: true
});

If you come up with default domain in Firebase hosting, that's fine until you add your own custom domain.

This can be solved by add your custom domain to Authorized Domains in Authentication -> Sign-in Method -> Authrorized Domains

Nguyễn Anh Tuấn
  • 1,023
  • 1
  • 12
  • 19
  • How can we add all subdomain with some wild card selector ? In our case we are creating subdomain for each user when they signup. How do we authorized them automatically ? – Santosh Feb 11 '22 at 06:15
  • @Santosh I don't think Firebase supports adding wildcard domain at this time. Unfortunately need to authorize it manually since it have some extra step regarding adding A record to your DNS and so on – Nguyễn Anh Tuấn Feb 11 '22 at 07:40
-1

To get past this error I had todo:

    const actionCodeSettings = {
    ¦ // URL you want to redirect back to. The domain (www.example.com) for this
    ¦ // URL must be in the authorized domains list in the Firebase Console.
    ¦ url: 'https://example.com',
    ¦ handleCodeInApp: true,
    };

then add example.com and www.example.com to my Authorized Domains.