Evelyn
Evelyn

Reputation: 2656

Android FirebaseUI Auth - How to reauthenticate?

Related Question: How does Firebase Auth UI deal with reauthentication? (This question is for iOS, and is unsolved)

I would like to allow a user to update their email/password/etc with FirebaseUI on Android.

According to the guide, the "drop-in" UI provides:

Account Management - flows to handle account management tasks, such as account creation and password resets.

On GitHub, it looks like the AuthUI Management Page feature is still in progress (right?)

So, I've created my own account management page, but some of the actions are security sensitive and require reauthentication:

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 and throws FirebaseAuthRecentLoginRequiredException.

The example code requires that we retrieve the credentials from the user before passing it to the reauthenticate:

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

// Get auth credentials from the user for re-authentication. The example below shows
// email and password credentials but there are multiple possible providers,
// such as GoogleAuthProvider or FacebookAuthProvider.
AuthCredential credential = EmailAuthProvider
        .getCredential("[email protected]", "password1234");

// Prompt the user to re-provide their sign-in credentials
user.reauthenticate(credential)
        .addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                Log.d(TAG, "User re-authenticated.");
            }
        });

However, getting the credentials from the user is non-trivial, since I allow sign in with Google, email, facebook, and phone number. For example, signing in with a phone number requires that a text be sent to the phone. This needs more than just an alert dialog asking for a password.

On Github, there was a merge for adding a reauthentication builder a few months ago, but I've been unable to find this function in the most recent FirebaseUI version. Something like AuthUI.createReauthIntentBuilder() would be perfect.

What is the best approach for re-authenticating a user with Firebase on Android? Can I use the AuthUI.createSignInIntent(), or is implementing my own reauthentication dialog really the only way?

Currently using: FirebaseUI Auth 3.1.2

Upvotes: 6

Views: 1186

Answers (1)

renal raion
renal raion

Reputation: 1

mUser.updateEmail(cek_email).addOnCompleteListener(new OnCompleteListener<Void>() {
    @Override
    public void onComplete(@NonNull Task<Void> task) {
       if (task.isSuccessful()){
          Toast.makeText(getActivity(), "succes", Toast.LENGTH_SHORT).show();

       }
    }
});

use method updateEmail

Upvotes: -2

Related Questions