How do I sign out users in Firebase 3.0?

给你一囗甜甜゛ 提交于 2019-12-09 04:18:17

问题


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

This is what I have tried:

var rootRef = firebase.database().ref();
var loggedInUser = firebase.auth();

1. firebase.signOut(); 
2. loggedInUser.signOut(); 
3. rootRef.signOut();
4. signOut();
5. firebase.auth.signOut();

I get ... is not a function for every one of the five above. I know there is no issue with my reference to the new Firebase, since firebase.database().ref(); and firebase.auth(); does not throw error. I have also migrated the app in the console.


回答1:


In JavaScript you can sign out the user with:

firebase.auth().signOut().then(function() {
  console.log('Signed Out');
}, function(error) {
  console.error('Sign Out Error', error);
});



回答2:


firebase.auth().signOut()

simply it works for me!




回答3:


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<Void>() {
            public void onComplete(@NonNull Task<Void> 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();
}



回答4:


I don't know if I correctly understood, but if you want to sign out every user signed in: That's not possible since the code is running on the client and the auth state refers to the client running it.

You can't access every client connected to the firebase auth service since it would mean running code on the server side.

However there's an option to specify the duration of a session, which is the remember parameter in the auth section.



来源:https://stackoverflow.com/questions/37376708/how-do-i-sign-out-users-in-firebase-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!