Pregunta

I'm looking at this doc: https://www.firebase.com/docs/security/simple-login-overview.html and based on that it doesn't look like logout doesn't accept a callback. I tried passing one and got a response that it accepts 0 arguments. Is there a way to confirm logout was successful?

¿Fue útil?

Solución

On that same page, there is a section titled "Monitoring User Authentication State" that mentions that the callback you pass to the FirebaseSimpleLogin constructor function will be "invoked any time that the user's authentication state changed."

The first parameter (error) will be non-null if there was an error with the user logging in; the second parameter (user) will be non-null if the user is successfully logged in; and both will be null if the user is not logged in.

Here's the example from that page:

var chatRef = new Firebase('https://SampleChat.firebaseIO-demo.com');
var auth = new FirebaseSimpleLogin(chatRef, function(error, user) {
  if (error) {
    // an error occurred while attempting login
    console.log(error);
  } else if (user) {
    // user authenticated with Firebase
    console.log('User ID: ' + user.id + ', Provider: ' + user.provider);
  } else {
    // user is logged out
  }
});

It's worth noting that the function is called once when the object is created even if the user is not logged in (e.g., it will check to see if the user is authenticated right away, and if they aren't, it will call the callback with null for both values, just as if they had just logged out).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top