You can use Firebase Authentication to create and use temporary anonymous accounts to authenticate with Firebase. These temporary anonymous accounts can be used to allow users who haven't yet signed up to your app to work with data protected by security rules. If an anonymous user decides to sign up to your app, you can link their sign-in credentials to the anonymous account so that they can continue to work with their protected data in future sessions.
Before you begin
- If you haven't already, add Firebase to your Android project .
- In your module (app-level) Gradle file
(usually
<project>/<app-module>/build.gradle.ktsor<project>/<app-module>/build.gradle), add the dependency for the Firebase Authentication library for Android. We recommend using the Firebase Android BoM to control library versioning.dependencies { // Import the BoM for the Firebase platform implementation ( platform ( "com.google.firebase:firebase-bom:34.12.0" )) // Add the dependency for the Firebase Authentication library // When using the BoM , you don't specify versions in Firebase library dependencies implementation ( "com.google.firebase:firebase-auth" ) }
By using the Firebase Android BoM , your app will always use compatible versions of Firebase Android libraries.
(Alternative) Add Firebase library dependencies without using the BoM
If you choose not to use the Firebase BoM , you must specify each Firebase library version in its dependency line.
Note that if you use multiple Firebase libraries in your app, we strongly recommend using the BoM to manage library versions, which ensures that all versions are compatible.
dependencies { // Add the dependency for the Firebase Authentication library // When NOT using the BoM , you must specify versions in Firebase library dependencies implementation ( "com.google.firebase:firebase-auth:24.0.1" ) }
- If you haven't yet connected your app to your Firebase project, do so from the Firebase console .
- Enable anonymous auth:
- In the Firebase console , open the Auth section.
- On the Sign-in Methods page, enable the Anonymous sign-in method.
- Optional : If you've upgraded your project to Firebase Authentication with Identity Platform , you can enable automatic clean-up. When you enable this setting, anonymous accounts older than 30 days will be automatically deleted. In projects with automatic clean-up enabled, anonymous authentication will no longer count toward usage limits or billing quotas. See Automatic clean-up .
Authenticate with Firebase anonymously
When a signed-out user uses an app feature that requires authentication with Firebase, sign in the user anonymously by completing the following steps:
- In your activity's
onCreatemethod, get the shared instance of theFirebaseAuthobject:Kotlin
private lateinit var auth : FirebaseAuth // ... // Initialize Firebase Auth auth = Firebase . auth . kt

