在Firebase v3.0.1中实施注销的最佳方法是什么?更新后删除Firebase.unauth

Luk*_*kas 39 javascript authentication firebase ecmascript-6

使用最近由谷歌发布的新firebase 3.0.1.

之前,我们有Firebase.unauth()方法https://www.firebase.com/docs/web/api/firebase/unauth.html

但它是旧的API.我在新API中看不到任何相关内容:

https://firebase.google.com/docs/reference/node/index-all

你有什么解决方案?试图使用类似的东西:

Object.keys(localStorage).forEach(key => {
  if (key.indexOf('firebase') !== -1) {
    localStorage.removeItem(key);
  }
});
Run Code Online (Sandbox Code Playgroud)

Luk*_*kas 99

使用回调捕获错误:

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

或者像亚当提到的.catch.

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

或等待和try...catch如果内部异步功能

try {
  await firebase.auth().signOut();
  // signed out
} catch (e){
 // an error
} 
Run Code Online (Sandbox Code Playgroud)

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

感谢AndréKool的指示:-)


小智 10

Lukas Liesis有正确的firebase signOut()方法,但为了解决被拒绝的承诺,我.catch()改为使用了.

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