How to log out user from app when I delete his account on firebase?

一世执手 提交于 2019-12-10 12:26:11

问题


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)
    }

}

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!


回答1:


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
}

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



来源:https://stackoverflow.com/questions/43812875/how-to-log-out-user-from-app-when-i-delete-his-account-on-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!