在Firebase v3.0.1 +中实现注销的最佳方法? Firebase.unauth在更新后被删除 [英] Best way to implement logout in Firebase v3.0.1+? Firebase.unauth is removed after update

查看:108
本文介绍了在Firebase v3.0.1 +中实现注销的最佳方法? Firebase.unauth在更新后被删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用由Google最近发布的新的Firebase 3.0.1.

Using new firebase 3.0.1 which was recently published by google.

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

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

But it's old API. I can't see anything related in new API:

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

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

What are your solutions? Trying to use something like:

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

推荐答案

使用回调捕获错误:

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

或使用亚当(Adam)提到的.catch.

or with .catch as Adam mentioned.

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

或者在异步函数内部使用await和try...catch

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

感谢 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆