Best way to implement logout in Firebase v3.0.1+? Firebase.unauth is removed after update

前端 未结 3 1209
情深已故
情深已故 2021-02-06 20:59

Using new firebase 3.0.1 which was recently published by google.

Before, we had Firebase.unauth() method https://www.firebase.com/docs/web/api/firebase/una

3条回答
  •  北荒
    北荒 (楼主)
    2021-02-06 21:18

    catch error with callback:

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

    or with .catch as Adam mentioned.

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

    Or with await and try...catch if inside async function

    try {
      await firebase.auth().signOut();
      // signed out
    } catch (e){
     // an error
    } 
    

    https://firebase.google.com/docs/auth/web/password-auth#next_steps

    thanks AndréKool for directions :-)

提交回复
热议问题