Showing a custom domain during sign in
This document shows you how to customize the Identity Platform authentication handler so users see your domain when signing in.
Understand the default authentication handler
When you enable Identity Platform for your project, a unique subdomain
powered by Firebase Hosting is created automatically.
The domain takes the form of https://[PROJECT-ID].firebaseapp.com
.
By default, Identity Platform uses this domain to handle all OAuth, OIDC,
and SAML sign-in redirects.
Using the default domain has several benefits:
Use multiple domains with the same federated providers
Share a single callback URL across different services and domains
Works with providers that only support one callback URL per app
The downside of the default handler is that users will briefly see the
https://[PROJECT-ID].firebaseapp.com
URL when signing in.
Customize the authentication handler
To override the default handler with your custom handler, do the following:
From the Firebase console, connect your project to a custom domain.
In the Google Cloud console, go to the Identity Platform > Identity providers page.
Go to Identity providersSelect your identity provider.
In the Project settings side pane, click Add Domain, and add your custom domain.
Click Save.
In your app configuration, update the callback URL with your custom domain instead of the default domain. For example, change
https://myproject.firebaseapp.com/__/auth/handler
tohttps://auth.mycustomdomain.com/__/auth/handler
.
Update your client SDK configuration
Web
You can copy the initialization code for the client SDK from the
Google Cloud console. If you customize the authentication handler, you'll
need to update the authDomain
field to your custom domain:
Web version 9
import { initializeApp } from "firebase/app"; const firebaseConfig = { apiKey: "...", // By default, authDomain is '[YOUR_APP].firebaseapp.com'. // You may replace it with a custom domain. authDomain: '[YOUR_CUSTOM_DOMAIN]' }; const firebaseApp = initializeApp(firebaseConfig);
Web version 8
firebase.initializeApp({ apiKey: '...', // By default, authDomain is '[YOUR_APP].firebaseapp.com'. // You may replace it with a custom domain. authDomain: '[YOUR_CUSTOM_DOMAIN]' });
Android and iOS
To customize the authentication handler, use the following code:
Java
FirebaseAuth.getInstance().setCustomAuthDomain("[YOUR_CUSTOM_DOMAIN]");
Kotlin+KTX
Firebase.auth.setCustomAuthDomain("[YOUR_CUSTOM_DOMAIN]")
Swift
let auth = Auth.auth()
auth.customAuthDomain = "[YOUR_CUSTOM_DOMAIN]"
Objective-C
FIRAuth *auth = [FIRAuth auth];
auth.customAuthDomain("[YOUR_CUSTOM_DOMAIN]");