-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
This is related to #309 but because of the huge traffic / discussion over there I want to file a new clean issue about this piece.
For context this has already been release on Web and is coming in iOS:
https://github.com/firebase/firebaseui-web#upgrading-anonymous-users
This has two parts:
1 - New Flow Parameter
There will be a new boolean option to the intent builder, with the default as false:
AuthUI.getInstance()
.createSignInIntentBuilder()
// ...
.setAutoUpgradeAnonymousAccounts(true)
.build();Throughout the flow, wherever we previously called signInWith... or signUpWith... we will now do the following logic (pseudocode):
if (hasAnonymousUser() && shouldAutoUpgrade) {
linkAccount(...);
} else {
signIn(...);
}2 - Handling Link Failures
In the event that a link call fails, we will exit the flow with an error:
- New error code ANONYMOUS_UPGRADE_MERGE_CONFLICT
- The IdpResponse should contain the AuthCredential that we tried to link with but failed.
- The User in the IdpResponse will be the anonymous user.
When handling the error, the developer should:
- Read/cache the anonymous user data.
- Sign in with the AuthCredential. They must make sure not to react to the auth state changed event.
- Write the anonymous user cached data as appropriate to the new user.
- Trigger their own sign-in success logic.
Notes
In a future "phase" of this feature we can do something similar to what @SUPERCILEX has already done and handle the complete flow including data transfer. In this "minimal" phase though this will only be for advanced developers that can handle the data transfer and display any relevant UI during that operation.