Auth

You can use Firebase Authentication to allow users to sign in to your app using one or more sign-in methods, including email address and password sign-in, and federated identity providers such as Google Sign-in and Facebook Login.

Get Started

Sign Up new Users

To sign up new users, you need to create a form that allows new users to register with your app using their email address and a password. When a user completes the form, validate the email address and password provided by the user, then pass them to the Create User with Email and Password function:

BlueprintsC++
#include "Auth/Auth.h"
void UMyClass::CreateUser()
{
    // Creates a new user in Firebase with email and password.
    FAuth::CreateUserWithEmailAndPassword
    (
        /* The new user's email address. */
        TEXT("john.doe@mymail.org"),
        
        /* The new user's password. */
        TEXT("my_v€ry_s€cr€t_p4$$w0rd"),
        
        /* Callback called when the user has been created. */
        FSignInUserCallback::CreateLambda([](const EFirebaseAuthError Error, UUser* User) -> void
        {
            if (Error == EFirebaseAuthError::None)
            {
                // User created.
            }
            else
            {
                // Failed to create user. Handle error here.
            }
        })
    );
}
create user blueprint example

Sign in Existing Users

Create a form that allows existing users to sign in using their email address and password. When a user completes the form, call the SignInWithEmailAndPassword method:

BlueprintsC++
FAuth::SignInWithEmailAndPassword
(
    TEXT("john.doe@mymail.org"), 
    TEXT("my_v4ry_$€cr€t_p4$$w0rd"), 
    FSignInUserCallback::CreateLambda([](const EFirebaseAuthError Error, UUser* User) -> void
    {
        if (Error == EFirebaseAuthError::None)
        {
            // User signed in.
        }
        else
        {
            // An error occurred.
        }
    })
);
sign in user blueprint example

Set an Authentication State Listener and Get Account Data

To respond to sign-in and sign-out events, attach a listener to the global authentication object. This listener gets called whenever the user's sign-in state changes. Because the listener runs only after the authentication object is fully initialized and after any network calls have completed, it is the best place to get information about the signed-in user.

For example, to create a listener that gets information about the user when a user successfully signs in:

BlueprintsC++
FFirebaseFeaturesModule::OnAuthStateChanged().AddLambda([]() -> void
{
    UUser* const User = FAuth::CurrentUser();
    if (User)
    {
        // Signed In.
    }
    else
    {
        // Signed Out.
    }
});
auth events blueprint example

Manage Users in Firebase

Create a User

You create a new user in your Firebase project by calling the CreateUserWithEmailAndPassword method or by signing in a user for the first time using a federated identity provider, such as Google Sign-In or Facebook Login.

You can also create new password-authenticated users from the Authentication section of the Firebase console, on the Users page.

Get the currently signed-in user

The recommended way to get the current user is by setting a listener on the Auth object:

BlueprintsC++
FFirebaseFeaturesModule::OnAuthStateChanged().AddLambda([]() -> void
{
    UUser* const User = FAuth::CurrentUser();
    if (User)
    {
        // Signed In.
    }
    else
    {
        // Signed Out.
    }
});
auth state change blueprint example

By using a listener, you ensure that the Auth object isn't in an intermediate state — such as initialization — when you get the current user.

You can also get the currently signed-in user by calling CurrentUser. If a user isn't signed in, CurrentUser returns nullptr.

Note: CurrentUser() might also return nullptr because the Auth object has not finished initializing. If you use a listener to keep track of the user's sign-in status, you don't need to handle this case.

Persist a User's Credential

The user's credentials will be stored in the local keystore after a user is signed in. The local cache of user credentials can be deleted by signing the user out.

Get a User's Profile

To get a user's profile information, use the accessor methods of an instance of UUser. For example:

BlueprintsC++
UUser* const User = FAuth::CurrentUser();
check(User);
FString DisplayName = User->DisplayName();
FString PhotoURL    = User->PhotoUrl();
FString PhoneNumber = User->PhoneNumber();
FString UUID        = User->Uid();
FString Email       = User->Email();
user props blueprint example

Get a User's Provider-Specific Profile Information

To get the profile information retrieved from the sign-in providers linked to a user, use the ProviderData method. For example:

BlueprintsC++
UUser* const User = FAuth::CurrentUser();
if (User)
{
    for (const FUserInfoInterface& Data : User->ProviderData())
    {
        FString ProviderProfileUid   = Data.Uid;
        FString ProviderProfileEmail = Data.Email;
        // ...
    }
}
get providers blueprint example

Update a User's Profile

You can update a user's basic profile information — the user's display name and profile photo URL — with the UpdateUserProfile method. For example:

BlueprintsC++
FUserProfile Profile;
Profile.DisplayName = TEXT("A new display name");
Profile.PhotoUrl = TEXT("https://domain.com/new_image.png");
User->UpdateUserProfile(Profile);
update profile blueprint example

Set a User's Email Address

You can set a user's email address with the UpdateEmail method. For example:

BlueprintsC++
User->UpdateEmail(TEXT("newemail@mydomain.org") /*, Optional Callback */);
update user email blueprint example

Send a User a Verification Email

You can send an address verification email to a user with the SendEmailVerification method. For example:

BlueprintsC++
User->SendEmailVerification(/* Optional Callback */);
veritification email blueprint example

You can customize the email template that is used in Authentication section of the Firebase console, on the Email Templates page. See Email Templates in Firebase Help Center.

Set a User's Password

You can set a user's password with the UpdatePassword method. For example:

BlueprintsC++
// C++ example code not available yet.
update password blueprint example

Important: To set a user's password, the user must have signed in recently.

Send a Password Reset Email

You can send a password reset email to a user with the SendPasswordResetEmail method. For example:

BlueprintsC++
// C++ example code not available yet.
reset password with email blueprint example

You can customize the email template that is used in Authentication section of the Firebase console, on the Email Templates page. See Email Templates in Firebase Help Center.

You can also send password reset emails from the Firebase console.

Delete a User

You can delete a user account with the Delete method. For example:

BlueprintsC++
// C++ example code not available yet.
delete user blueprint example

Important: To delete a user, the user must have signed in recently.

You can also delete users from the Authentication section of the Firebase console, on the Users page.

Re-Authenticate a User

Some security-sensitive actions—such as deleting an account, setting a primary email address, and changing a password—require that the user has recently signed in. If you perform one of these actions, and the user signed in too long ago, the action fails.

When this happens, re-authenticate the user by getting new sign-in credentials from the user and passing the credentials to Reauthenticate. For example:

BlueprintsC++
// C++ example code not available yet.
reauthenticate user blueprint example

Thirdparty Providers

Google Sign-In

There are two ways to get credential for Google Sign-In.

The first is to use the Sign In and Get Credential from Google method. Under the hood, this method will do the following:

  1. Sign the current user into Google Sign-In, pausing the app and prompting the Google Sign-In form if required.
  2. Create a Credential object based on the signed in user.
Google Sign-In: Method 1 (iOS & Android)

Start by enabling Google Sign-In in the Firebase Console. Then fill out the settings in Firebase Features's settings.

Then use the following code to show the login screen

BlueprintsC++
#include "Auth/Auth.h"
#include "Google/GoogleServices.h"
#include "Auth/Credential.h"
// First, signs in with the Google Sign-In SDK to retrieve the required
// data to authenticate against Firebase.
UGoogleServicesLibrary::SignIn
(
    /* ServerClientID */
    TEXT("{server-client-id}"),
        
    /* bSkipIfSigned */
    false,
        
    /* bUseSilentSignIn */
    true,
    /* Callback */
    FGoogleSignInCallback::CreateLambda([](bool bSuccess, FString ErrorMessage) -> void
    {
        // The user completed the Google Sign-In and is now authenticated against the 
        // Google Sign-In SDK.
        if (bSuccess)
        {
            // Gets the data required for the Firebase backend.
            const FString IdToken     = UGoogleServicesLibrary::GetIdToken();
            const FString AccessToken = UGoogleServicesLibrary::GetAccessToken();
            // Creates a credential for the backend.
            FCredential GoogleCredential = UCredentialLibrary::GetCredentialFromGoogle(IdToken, AccessToken);
            // And uses this credential to finally authenticate for Firebase.
            FAuth::SignInWithCredential(GoogleCredential, FSignInUserCallback::CreateLambda(
                [](const EFirebaseAuthError Error, UUser* User) -> void
            {
                // Checks for success.
                if (Error == EFirebaseAuthError::None)
                {
                    // The user is authenticated, user data can be accessed.
                }
                // Failed to authenticate.
                else
                {
                    // Simply log the error code.
                    UE_LOG(LogTemp, Error, TEXT("Failed to authenticate against Firebase. Code: %d"), Error);
                }
            }));
        }
        // An error occurred or the user canceled the Google Sign-In overlay.
        else
        {
            // We just print the error to logs.
            UE_LOG(LogTemp, Error, TEXT("Failed to sign-in against Google, reason: %s"), *ErrorMessage);
        }
    })
);
google sign in blueprint example

The Server Client ID is called Web Client ID in the Firebase Console.

Google Sign-In: Method 2 (Any Platform)

The second method is to use the Get Credential from Google node. This node requires two tokens that must be obtained from the Google Sign-In SDK or the Desktop login flow after authenticating the user with it.

BlueprintsC++
// C++ example code not available yet.
Google signing with token blueprint example

Game Center

Sign in with Game Center can be implemented on Apple devices with the following code:

BlueprintsC++
// C++ example code not available yet.
Game Center signin blueprint example

Make sure you enabled GameCenter in your iOS provision.

Sign In with Apple

Sign in with Apple can be implemented with the following code on iOS:

BlueprintsC++
// C++ example code not available yet.
Signin with apple unreal engine blueprint example

Make sure you enabled Apple Sign-In support in your mobile provision.

Sign In with Facebook

  1. Go to Facebook's Login page and create an app for the target platform.
  2. Enable Facebook as a sign-in provider in the Firebase Console.
  3. In the Editor, open the project's settings and fill the client ID given by Facebook.
setup facebook blueprint

Now you can simply add the following node on the click of the button

BlueprintsC++
// C++ example code not available yet.
signin with google playgames blueprint example

Sign In with Google Play Games

BlueprintsC++
// C++ example code not available yet.
signin with google playgames blueprint example

Other Providers

Examples for the other providers are coming soon.