use of com.google.firebase.auth.FirebaseUser in project Firebase-Login by jocelin09.
the class ProfileActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// initializing firebase authentication object
firebaseAuth = FirebaseAuth.getInstance();
// Then we need a GoogleSignInOptions object
// And we need to build it as below
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken(getString(R.string.default_web_client_id)).requestEmail().build();
// Then we will get the GoogleSignInClient object from GoogleSignIn class
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
// that means current user will return null
if (firebaseAuth.getCurrentUser() == null) {
// closing this activity
finish();
// starting login activity
startActivity(new Intent(this, LoginActivity.class));
}
// getting current user
FirebaseUser user = firebaseAuth.getCurrentUser();
// initializing views
textViewUserEmail = (TextView) findViewById(R.id.textViewUserEmail);
buttonLogout = (Button) findViewById(R.id.buttonLogout);
// displaying logged in user name
// textViewUserEmail.setText("Welcome " + user.getEmail());
textViewUserEmail.setText("Welcome ");
// adding listener to button
buttonLogout.setOnClickListener(this);
}
use of com.google.firebase.auth.FirebaseUser in project FirebaseUI-Android by firebase.
the class AuthUI method delete.
/**
* Delete the use from FirebaseAuth and delete any associated credentials from the Credentials
* API. Returns a {@link Task} that succeeds if the Firebase Auth user deletion succeeds and
* fails if the Firebase Auth deletion fails. Credentials deletion failures are handled
* silently.
*
* @param context the calling {@link Context}.
*/
@NonNull
public Task<Void> delete(@NonNull final Context context) {
final FirebaseUser currentUser = mAuth.getCurrentUser();
if (currentUser == null) {
return Tasks.forException(new FirebaseAuthInvalidUserException(String.valueOf(CommonStatusCodes.SIGN_IN_REQUIRED), "No currently signed in user."));
}
final List<Credential> credentials = getCredentialsFromFirebaseUser(currentUser);
// Ensure the order in which tasks are executed properly destructures the user.
return signOutIdps(context).continueWithTask(task -> {
// Propagate exception if there was one
task.getResult();
if (!GoogleApiUtils.isPlayServicesAvailable(context)) {
Log.w(TAG, "Google Play services not available during delete");
return Tasks.forResult((Void) null);
}
final CredentialsClient client = GoogleApiUtils.getCredentialsClient(context);
List<Task<?>> credentialTasks = new ArrayList<>();
for (Credential credential : credentials) {
credentialTasks.add(client.delete(credential));
}
return Tasks.whenAll(credentialTasks).continueWith(task1 -> {
Exception e = task1.getException();
Throwable t = e == null ? null : e.getCause();
if (!(t instanceof ApiException) || ((ApiException) t).getStatusCode() != CommonStatusCodes.CANCELED) {
// doesn't mean fully deleting the user failed.
return task1.getResult();
}
return null;
});
}).continueWithTask(task -> {
// Propagate exception if there was one
task.getResult();
return currentUser.delete();
});
}
use of com.google.firebase.auth.FirebaseUser in project FirebaseUI-Android by firebase.
the class AnonymousUpgradeActivity method updateUI.
private void updateUI() {
FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
if (currentUser == null) {
// Not signed in
mBinding.anonSignIn.setEnabled(true);
mBinding.beginFlow.setEnabled(false);
mBinding.resolveMerge.setEnabled(false);
mBinding.signOut.setEnabled(false);
} else if (mPendingCredential == null && currentUser.isAnonymous()) {
// Anonymous user, waiting for linking
mBinding.anonSignIn.setEnabled(false);
mBinding.beginFlow.setEnabled(true);
mBinding.resolveMerge.setEnabled(false);
mBinding.signOut.setEnabled(true);
} else if (mPendingCredential == null && !currentUser.isAnonymous()) {
// Fully signed in
mBinding.anonSignIn.setEnabled(false);
mBinding.beginFlow.setEnabled(false);
mBinding.resolveMerge.setEnabled(false);
mBinding.signOut.setEnabled(true);
} else if (mPendingCredential != null) {
// Signed in anonymous, awaiting merge conflict
mBinding.anonSignIn.setEnabled(false);
mBinding.beginFlow.setEnabled(false);
mBinding.resolveMerge.setEnabled(true);
mBinding.signOut.setEnabled(true);
}
}
use of com.google.firebase.auth.FirebaseUser in project FirebaseUI-Android by firebase.
the class SignedInActivity method onCreate.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
if (currentUser == null) {
startActivity(AuthUiActivity.createIntent(this));
finish();
return;
}
IdpResponse response = getIntent().getParcelableExtra(ExtraConstants.IDP_RESPONSE);
mBinding = SignedInLayoutBinding.inflate(getLayoutInflater());
setContentView(mBinding.getRoot());
populateProfile(response);
populateIdpToken(response);
mBinding.deleteAccount.setOnClickListener(view -> deleteAccountClicked());
mBinding.signOut.setOnClickListener(view -> signOut());
}
use of com.google.firebase.auth.FirebaseUser in project FirebaseUI-Android by firebase.
the class EmailLinkSignInHandler method handleNormalFlow.
private void handleNormalFlow(final AuthOperationManager authOperationManager, final EmailLinkPersistenceManager persistenceManager, final String email, final String link) {
final AuthCredential emailLinkCredential = EmailAuthProvider.getCredentialWithLink(email, link);
// Bug in core SDK - credential is mutated and won't be usable for sign in, so create
// a new one to pass back. b/117425827
final AuthCredential emailLinkCredentialForLinking = EmailAuthProvider.getCredentialWithLink(email, link);
// Either regular sign in or anonymous user upgrade
authOperationManager.signInAndLinkWithCredential(getAuth(), getArguments(), emailLinkCredential).addOnSuccessListener(authResult -> {
persistenceManager.clearAllData(getApplication());
FirebaseUser user = authResult.getUser();
IdpResponse response = new IdpResponse.Builder(new User.Builder(EMAIL_LINK_PROVIDER, user.getEmail()).setName(user.getDisplayName()).setPhotoUri(user.getPhotoUrl()).build()).build();
handleSuccess(response, authResult);
}).addOnFailureListener(e -> {
persistenceManager.clearAllData(getApplication());
if (e instanceof FirebaseAuthUserCollisionException) {
handleMergeFailure(emailLinkCredentialForLinking);
} else {
setResult(Resource.forFailure(e));
}
});
}
Aggregations