Jacques.S
Jacques.S

Reputation: 3623

Firebase says "Domain not whitelisted" for a link that is whitelisted

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.

Upvotes: 56

Views: 42787

Answers (6)

Julien Reszka
Julien Reszka

Reputation: 1359

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

Click on "Authorized domains"

Click on "Add domain"

enter image description here

Still not working ?

www.example.com is not the same thing as example.com

Upvotes: 22

Peter
Peter

Reputation: 13505

If you have already added your domain in firebase console, and you still get this problem - it may be just that your authorized domain doesn't have the www prefix. In my case, I added both

MY_DOMAIN.com and www.MY_DOMAIN.com to the Authorized domains in

https://console.firebase.google.com -> Authentication -> Settings -> Authorised Domains

And now it works

Upvotes: 1

philipeaudemars
philipeaudemars

Reputation: 31

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.

Upvotes: 1

Nguyễn Anh Tuấn
Nguyễn Anh Tuấn

Reputation: 1350

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

firebase
  .auth()
  .sendSignInLinkToEmail('[email protected]', {
    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

Upvotes: 4

Jacques.S
Jacques.S

Reputation: 3623

  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

Upvotes: 81

Jack&#39;
Jack&#39;

Reputation: 2526

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

Upvotes: 2

Related Questions