Register a callback on a Future

Some programs have Update functions that are called 30 or 60 times per second.
For example, many games follow this model. These programs can call the LastResult
functions to poll asynchronous calls.
However, if your program is event driven, you may prefer to register callback functions.
A callback function is called upon completion of the Future.

void CreateUserUsingLambda(firebase::auth::Auth* auth) {
// Callbacks work the same for any firebase::Future.
firebase::Future<firebase::auth::User*> result =
auth->CreateUserWithEmailAndPasswordLastResult();
// The lambda has the same signature as the callback function.
result.OnCompletion(
[](const firebase::Future<firebase::auth::User*>& result,
void* user_data) {
// `user_data` is the same as &my_program_context, below.
// Note that we can't capture this value in the [] because std::function
// is not supported by our minimum compiler spec (which is pre C++11).
MyProgramContext* program_context =
static_cast<MyProgramContext*>(user_data);
// Process create user result...
(void)program_context;
},
&my_program_context);
}

Next steps

After a user signs in for the first time, a new user account is created and
linked to the credentials—that is, the user name and password, phone
number, or auth provider information—the user signed in with. This new
account is stored as part of your Firebase project, and can be used to identify
a user across every app in your project, regardless of how the user signs in.

In your apps, you can get the user's basic profile information from the
firebase::auth::User object: