213 words
1 minute

Getting Started with Firebase Authentication in Unity

2022-11-15
Views —

I was looking for a third-party account SDK for an app aimed at international users. After comparing the options, I chose Firebase.

Integration was initially rough. I tried exporting an AAR from Android Studio into Unity, then exporting an Android Studio project from Unity. Neither attempt worked. I had not yet tried iOS.

The real problem was that I had not read the official documentation carefully. Google supplied a Unity package: importing it and doing a little configuration in the Firebase console was much simpler.

Official Firebase Authentication Unity guide

Register the app in Firebase#

Registering the app in the Firebase console

Make sure the registered package name matches the app’s final package name.

Add the SHA certificate fingerprint#

Add the fingerprint in the app settings:

Adding a SHA certificate fingerprint

Download google-services.json#

In the project described in this November 2022 note, I placed the file in Asset/StreamingAssets in the Unity project.

Enable an authentication provider#

Enabling an authentication provider

Import FirebaseAuth.unitypackage#

Import the authentication package into Unity.

Add test code#

The following code tests account creation with an email address and password:

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.
FirebaseUser newUser = task.Result;
Debug.LogFormat(
"Firebase user created successfully: {0} ({1})",
newUser.DisplayName,
newUser.UserId
);
});
Getting Started with Firebase Authentication in Unity
https://blog.coding1024.com/en/posts/cd4d0695/
Author
huangjx
Published at
2022-11-15
License
CC BY-NC-SA 4.0

Comments

Questions, ideas and experiences are welcome. Please be kind and avoid sharing private information.

Loading comments…