How do I sign out users in Firebase 3.0?

后端 未结 5 1670
甜味超标
甜味超标 2021-02-03 19:09

According to documentation, I force a user to sign out with the method signOut().

This is what I have tried:

var rootRef = firebase.database         


        
5条回答
  •  天命终不由人
    2021-02-03 19:54

    There have several way to sign out user:

    1. FirebaseUI: Refarence

    Add depenencies:

    dependencies {
        implementation 'com.firebaseui:firebase-ui-auth:4.0.0'
    }
    

    Then:

    public void onClick(View v) {
    if (v.getId() == R.id.sign_out) {
        AuthUI.getInstance()
            .signOut(this)
            .addOnCompleteListener(new OnCompleteListener() {
                public void onComplete(@NonNull Task task) {
                    // user is now signed out
                    startActivity(new Intent(MyActivity.this, SignInActivity.class));
                    finish();
                }
            });
        }
    }
    

    2. Kotlin: Referance

    Use Android default Authentication dependency, ex: com.google.firebase:firebase-auth:16.0.1

    firebase.auth().signOut().then(function() {
      // Sign-out successful.
    }).catch(function(error) {
      // An error happened.
    });
    

    3. Default with java:

    Use Android default Authentication dependency, ex: com.google.firebase:firebase-auth:16.0.1

    FirebaseUser user = mAuth.getCurrentUser();
    if (user != null){
        mAuth.signOut();
        Toast.makeText(this, user.getEmail()+ " Sign out!", Toast.LENGTH_SHORT).show();
    }else{
        Toast.makeText(this, "You aren't login Yet!", Toast.LENGTH_SHORT).show();
    }
    

提交回复
热议问题