在Firebase上删除用户帐户后,如何从应用程序中注销用户? [英] How to log out user from app when I delete his account on firebase?

查看:60
本文介绍了在Firebase上删除用户帐户后,如何从应用程序中注销用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Firebase控制台上删除帐户时,用户仍然登录到我的应用程序时,我使用此代码来保持用户的登录状态. 删除用户帐户后如何注销用户?

When I delete an account on my Firebase console, the user stills logged in to my app, I use this code to keep the user logged. How can I log out the user when I delete his account?

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控制台上继续运行). 希望有人可以帮助我!!! 预先感谢!

But I don't know how to check if the account that is using the user is valid or not (if the account continues at the firebase console or not) before the "automatic log in". Hope someone can help me out!!! Thanks in advance!

推荐答案

我们也有类似的实现,因此希望可以解决您的问题.

We have similar implementation, so hopefully this solves your problem.

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通信以获取新的身份验证令牌,如果删除了用户,该令牌将失败.

This forces Auth to communicate with Firebase to get a new authentication token, which would fail if the user was deleted.

这篇关于在Firebase上删除用户帐户后,如何从应用程序中注销用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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