Get Started with Firebase Authentication in Unity Stay organized with collections Save and categorize content based on your preferences.
You can useFirebase Authentication to allow users to sign in to your game using oneor more sign-in methods, including email address and password sign-in, andfederated identity providers such as Google Sign-in and Facebook Login. Thistutorial gets you started withFirebase Authentication by showing you how to addemail address and password sign-in to your game.
Before you begin
Before you can useFirebase Authentication,you need to:
Register your Unity project and configure it to use Firebase.
If your Unity project already uses Firebase, then it's alreadyregistered and configured for Firebase.
If you don't have a Unity project, you can download asample app.
Add theFirebaseUnity SDK (specifically,
FirebaseAuth.unitypackage) toyour Unity project.
Note that adding Firebase to your Unity project involves tasks both in theFirebase console and in your open Unity project(for example, you download Firebase config files from the console, then movethem into your Unity project).
Sign up new users
Create a form that allows new users to register with your game using their emailaddress and a password. When a user completes the form, validate the emailaddress and password provided by the user, then pass them to theCreateUserWithEmailAndPasswordAsync method:
auth=Firebase.Auth.FirebaseAuth.DefaultInstance;auth.CreateUserWithEmailAndPasswordAsync(email,password).ContinueWith(task=>{if(task.IsCanceled){Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled.");return;}if(task.IsFaulted){Debug.LogError("CreateUserWithEmailAndPasswordAsync encountered an error: "+task.Exception);return;}// Firebase user has been created.Firebase.Auth.AuthResultresult=task.Result;Debug.LogFormat("Firebase user created successfully: {0} ({1})",result.User.DisplayName,result.User.UserId);});Sign in existing users
Create a form that allows existing users to sign in using their email addressand password. When a user completes the form, call theSignInWithEmailAndPasswordAsync method:
auth=Firebase.Auth.FirebaseAuth.DefaultInstance;auth.SignInWithEmailAndPasswordAsync(email,password).ContinueWith(task=>{if(task.IsCanceled){Debug.LogError("SignInWithEmailAndPasswordAsync was canceled.");return;}if(task.IsFaulted){Debug.LogError("SignInWithEmailAndPasswordAsync encountered an error: "+task.Exception);return;}Firebase.Auth.AuthResultresult=task.Result;Debug.LogFormat("User signed in successfully: {0} ({1})",result.User.DisplayName,result.User.UserId);});Set an authentication state change event handler and get user data
To respond to sign-in and sign-out events, attach an event handler to the globalauthentication object. This handler gets called whenever the user's sign-instate changes. Because the handler runs only after the authentication object isfully initialized and after any network calls have completed, it is the bestplace to get information about the signed-in user.
Register the event handler using theFirebaseAuth object'sStateChangedfield. When a user successfully signs in, you can get information about the userin the event handler.
Finally, when this object hasDestroy called on it, it will automatically callOnDestroy. Clean up the Auth object's references inOnDestroy.
voidInitializeFirebase(){auth=Firebase.Auth.FirebaseAuth.DefaultInstance;auth.StateChanged+=AuthStateChanged;AuthStateChanged(this,null);}voidAuthStateChanged(objectsender,System.EventArgseventArgs){if(auth.CurrentUser!=user){boolsignedIn=user!=auth.CurrentUser &&auth.CurrentUser!=null &&auth.CurrentUser.IsValid();if(!signedIn &&user!=null){Debug.Log("Signed out "+user.UserId);}user=auth.CurrentUser;if(signedIn){Debug.Log("Signed in "+user.UserId);displayName=user.DisplayName??"";emailAddress=user.Email??"";photoUrl=user.PhotoUrl??"";}}}voidOnDestroy(){auth.StateChanged-=AuthStateChanged;auth=null;}Next steps
Learn how to add support for other identity providers and anonymous guestaccounts:
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-06 UTC.