use of com.firebase.ui.auth.ui.TaskFailureLogger in project FirebaseUI-Android by firebase.
the class WelcomeBackIdpPrompt method onSuccess.
@Override
public void onSuccess(final IdpResponse idpResponse) {
if (idpResponse == null) {
// do nothing
return;
}
AuthCredential newCredential = AuthCredentialHelper.getAuthCredential(idpResponse);
if (newCredential == null) {
Log.e(TAG, "No credential returned");
finish(ResultCodes.CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
return;
}
FirebaseUser currentUser = mActivityHelper.getCurrentUser();
if (currentUser == null) {
mActivityHelper.getFirebaseAuth().signInWithCredential(newCredential).addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult result) {
if (mPrevCredential != null) {
result.getUser().linkWithCredential(mPrevCredential).addOnFailureListener(new TaskFailureLogger(TAG, "Error signing in with previous credential " + idpResponse.getProviderType())).addOnCompleteListener(new FinishListener(idpResponse));
} else {
finish(ResultCodes.OK, IdpResponse.getIntent(idpResponse));
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
finishWithError();
}
}).addOnFailureListener(new TaskFailureLogger(TAG, "Error signing in with new credential " + idpResponse.getProviderType()));
} else {
currentUser.linkWithCredential(newCredential).addOnFailureListener(new TaskFailureLogger(TAG, "Error linking with credential " + idpResponse.getProviderType())).addOnCompleteListener(new FinishListener(idpResponse));
}
}
use of com.firebase.ui.auth.ui.TaskFailureLogger in project FirebaseUI-Android by firebase.
the class CredentialSignInHandler method onComplete.
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser firebaseUser = task.getResult().getUser();
mHelper.saveCredentialsOrFinish(mSmartLock, mActivity, firebaseUser, mResponse);
} else {
if (task.getException() instanceof FirebaseAuthUserCollisionException) {
final String email = mResponse.getEmail();
if (email != null) {
mHelper.getFirebaseAuth().fetchProvidersForEmail(email).addOnFailureListener(new TaskFailureLogger(TAG, "Error fetching providers for email")).addOnSuccessListener(new StartWelcomeBackFlow()).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// TODO: What to do when signing in with Credential fails
// and we can't continue to Welcome back flow without
// knowing providers?
}
});
return;
}
} else {
Log.e(TAG, "Unexpected exception when signing in with credential " + mResponse.getProviderType() + " unsuccessful. Visit https://console.firebase.google.com to enable it.", task.getException());
}
mHelper.dismissDialog();
}
}
use of com.firebase.ui.auth.ui.TaskFailureLogger in project FirebaseUI-Android by firebase.
the class IdpSignInContainer method onSuccess.
@Override
public void onSuccess(final IdpResponse response) {
AuthCredential credential = AuthCredentialHelper.getAuthCredential(response);
mHelper.getFirebaseAuth().signInWithCredential(credential).addOnFailureListener(new TaskFailureLogger(TAG, "Failure authenticating with credential " + credential.getProvider())).addOnCompleteListener(new CredentialSignInHandler(getActivity(), mHelper, mSaveSmartLock, RC_WELCOME_BACK_IDP, response));
}
use of com.firebase.ui.auth.ui.TaskFailureLogger in project FirebaseUI-Android by firebase.
the class RegisterEmailFragment method registerUser.
private void registerUser(final String email, final String name, final String password) {
mHelper.getFirebaseAuth().createUserWithEmailAndPassword(email, password).addOnFailureListener(new TaskFailureLogger(TAG, "Error creating user")).addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
// Set display name
UserProfileChangeRequest changeNameRequest = new UserProfileChangeRequest.Builder().setDisplayName(name).setPhotoUri(mUser.getPhotoUri()).build();
final FirebaseUser user = authResult.getUser();
user.updateProfile(changeNameRequest).addOnFailureListener(new TaskFailureLogger(TAG, "Error setting display name")).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
// This executes even if the name change fails, since
// the account creation succeeded and we want to save
// the credential to SmartLock (if enabled).
mHelper.saveCredentialsOrFinish(mSaveSmartLock, getActivity(), user, password, new IdpResponse(EmailAuthProvider.PROVIDER_ID, email));
}
});
}
}).addOnFailureListener(getActivity(), new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
mHelper.dismissDialog();
if (e instanceof FirebaseAuthWeakPasswordException) {
// Password too weak
mPasswordInput.setError(getResources().getQuantityString(R.plurals.error_weak_password, R.integer.min_password_length));
} else if (e instanceof FirebaseAuthInvalidCredentialsException) {
// Email address is malformed
mEmailInput.setError(getString(R.string.invalid_email_address));
} else if (e instanceof FirebaseAuthUserCollisionException) {
// Collision with existing user email, it should be very hard for
// the user to even get to this error due to CheckEmailFragment.
mEmailInput.setError(getString(R.string.error_user_collision));
} else {
// General error message, this branch should not be invoked but
// covers future API changes
mEmailInput.setError(getString(R.string.email_account_creation_error));
}
}
});
}
use of com.firebase.ui.auth.ui.TaskFailureLogger in project FirebaseUI-Android by firebase.
the class AuthMethodPickerActivity method onSuccess.
@Override
public void onSuccess(final IdpResponse response) {
AuthCredential credential = AuthCredentialHelper.getAuthCredential(response);
mActivityHelper.getFirebaseAuth().signInWithCredential(credential).addOnFailureListener(new TaskFailureLogger(TAG, "Firebase sign in with credential " + credential.getProvider() + " unsuccessful. Visit https://console.firebase.google.com to enable it.")).addOnCompleteListener(new CredentialSignInHandler(this, mActivityHelper, mSaveSmartLock, RC_ACCOUNT_LINK, response));
}
Aggregations