Learn how to integrate Clerk into your Firebase application
Learn more about Clerk and Firebase.
This integration configures Clerk as a custom authentication system for your Firebase services. It enables Clerk-managed users to authenticate and interact directly with Firebase's suite of tools, including Realtime Database, Cloud Functions, and Cloud Storage.
Check out our example application showcasing how to integrate Clerk with Firebase: https://github.com/clerkinc/clerk-firebase-starter
1. Turn on the integration
To enable the integration, you will need to provide Clerk with the required Firebase configuration attributes depending on the Firebase features you would require authenticated user access to.
To get started, turn on the Firebase integration in the Clerk Dashboard:
Your Application & instance → Integrations → Firebase
2. Integration configuration
To allow Clerk to generate the required authentication token for Firebase, you will need to set some configuration attributes on the Clerk integration page.
1. (Easy way) Upload a JSON Firebase configuration file
You can upload the JSON configuration file you will retrieve from Firebase directly on the integrations page and the required fields will be filled in automatically.
- To get the Firebase JSON configuration file, navigate to your Project Settings → Service Accounts → Firebase Admin SDK and then click the Generate new private key button.
- To upload the file on Clerk, use the Upload JSON button on the Firebase integration screen inside the configuration modal:
2. Fill in the required attributes manually
The attributes that you need to fill in to connect Clerk with Firebase, as a custom authentication system, are described below:
- Service account ID The service account ID can be found in the Google Cloud Console for your Firebase project, or in the
client_emailfield of a service account JSON file.
- Project ID The Firebase project ID is the unique identifier of your Firebase project. Can be found under the Project Settings in the Firebase platform.
- Database URL (Optional)The Firebase Realtime Database URL as retrieved from the Firebase platform under the Realtime Database page.
- Private Key The private key used for signing which belongs to the Google service account ID of your project. Can be found in the Google Cloud Console for your Firebase project, or in the
private_keyfield of a service account JSON file.
3. Firebase user sign-in with Clerk as an authentication provider
After successfully completing the integration setup on your dashboard, you should setup your frontend to connect Clerk with the Firebase authentication system.
1. Retrieve a Firebase user authentication token from Clerk
The Firebase Web SDK requires an authentication token to sign in your users using Clerk as the custom authentication provider. This token can be retrieved calling the
getToken method returned from the
useAuth() hook and calling it with the
"integration_firebase" template parameter.
The above method will return the token needed for the Firebase Web SDK to sign in your users with Clerk.
2. Sign-in using the Firebase Web SDK
To authenticate your users on Firebase using Clerk you would need to call the
signInWithCustomToken method of the Firebase Auth scope.
An example implementation using Next.js: