Firebase 注销在 Swift 中不起作用 [英] Firebase sign out not working in Swift
问题描述
我正在使用最新的 Firebase API (3.2.1) 并且我正在使用此代码来检查用户是否已登录:
I am using newest Firebase API (3.2.1) and I am using this code to check if user is signed in:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if(self.navigationController != nil){
self.navigationController!.setNavigationBarHidden(true, animated: true)
}
if(FIRAuth.auth() != nil){
self.performSegueWithIdentifier("loginSuccessSegue", sender: self)
}
}
换句话说,如果存在 auth 对象,我将切换到其他控制器.在那个控制器上,我有退出按钮,它是这样退出的:
In other words if auth object is present I am switching to other controller. On that controller I have sign out button which is doing sign out like this:
do{
try FIRAuth.auth()?.signOut()
self.performSegueWithIdentifier("logoutSegue", sender: self)
}catch{
print("Error while signing out!")
}
我在这个操作中没有出错,但是当我切换到登录控制器时,这个 auth 对象存在并且我再次切换回带有数据的控制器.我还尝试在 auth 中检查当前用户对象,它存在且有效.
I do not get error on this operation but when I am switched to login controller, this auth object is present and I get switched back again to controller with data. I also tried checking the current user object in auth and it is present and valid.
有人知道我如何正确退出吗?
Anyone knows how an I properly do sign out?
推荐答案
2020 ...
do { try Auth.auth().signOut() }
catch { print("already logged out") }
通常,在您的基地"上屏幕,类似......
Typically, on your "base" screen, something like ...
func logoutUser() {
// call from any screen
do { try Auth.auth().signOut() }
catch { print("already logged out") }
navigationController?.popToRootViewController(animated: true)
}
这篇关于Firebase 注销在 Swift 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!