当我在我的 Firebase 控制台上删除一个帐户时,用户仍然登录到我的应用程序,我使用此代码让用户保持登录状态。 删除他的帐户后如何注销用户?
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
//check if user is logged in
if FIRAuth.auth()?.currentUser != nil {
//if user if logged in
let vc = self.storyboard?.instantiateViewController(withIdentifier: "mainVC")
self.present(vc!, animated: false, completion: nil)
}
}
但我不知道如何在“自动登录”之前检查正在使用该用户的帐户是否有效(该帐户是否继续在 firebase 控制台上运行)。 希望有人能帮帮我!!! 提前致谢!
最佳答案
我们有类似的实现,因此希望这可以解决您的问题。
if let currentUser = Auth.auth().currentUser {
currentUser.getIDTokenForcingRefresh(true) { error in
if let error = error {
// log out
} else {
// go in
}
}
} else {
// log in
}
这会强制 Auth 与 Firebase 通信以获取新的身份验证 token ,如果用户被删除,该 token 将会失败。
关于ios - 当我在 firebase 上删除用户帐户时,如何从应用程序中注销用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43812875/