从Firebase中删除帐户是否会自动注销用户? [英] Does deleting account from Firebase automatically logs user out?

查看:86
本文介绍了从Firebase中删除帐户是否会自动注销用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,从Firebase中删除帐户会自动注销用户吗?
我的意思是,如果要在删除登录屏幕后向他显示用户,那么我只需要提供该VC?
之所以问这个问题,是因为如果我这样做,它会崩溃,并且我认为这是因为此时用户已不存在.

我可以吗?

I would like to know, does deleting account from Firebase automatically logs user out?
I mean, if I want to show him after deleting the login screen, then I just have to present that VC?
I am asking this because if I do like this, it crashes and I think it is because the user doesn't exists anymore at this points.

Am I right?

带有一些说明的代码:

let user = FIRAuth.auth()?.currentUser

user?.deleteWithCompletion { error in
  if let error = error {
    // An error happened.
  } else {
     try! FIRAuth.auth()!.signOut()//This is unnecessary?

            let mainStoryboard: UIStoryboard = UIStoryboard(name:"Main",bundle:nil)

            let WelcomeViewController: UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "WelcomeViewController")

            //Send the user to the WelcomeViewController
            self.present(WelcomeViewController, animated: true, completion: nil)
    // Account deleted. 
  }
}

推荐答案

如果要删除 currentUser ,则需要注意以下两点:-

If you are deleting your currentUser you need to take care of two things:-

  • Firebase数据库中删除用户的数据(如果有的话)
  • 删除身份验证凭据(例如:-电子邮件密码,facebook登录名,twitter等)

  • Delete the user's data from the Firebase Database (If there is any)
  • Delete the auth Credentials (e.g :- email-password, facebook login, twitter etc)

要删除当前用户,请使用以下功能,该功能还会先注销用户

To delete your current user use the below function, which also first sign's out the user

 FIRAuth.auth()?.currentUser?.delete(completion: { (err) in

    print(err?.localizedDescription)

})

如果您对删除功能进行CMD + CLICK,将带您进入其文档:-

If you CMD+CLICK on the delete function it will take you to its documentation :-

删除用户帐户(如果这是当前用户,则也注销该用户).

Deletes the user account (also signs out the user, if this was the current user).

完成(可选);当删除帐户的请求完成或失败时调用的块.将来会在主线程上异步调用.

completion Optionally; the block invoked when the request to delete the account is complete, or fails. Invoked asynchronously on the main thread in the future.

可能的错误代码: -@c FIRAuthErrorCodeRequiresRecentLogin-更新电子邮件是一项安全敏感的操作,需要用户最近登录.此错误表示用户最近没有登录过.要解决此问题,请通过在FIRUser上调用reauthenticateWithCredential:completion:来重新认证用户.

Possible error codes: - @c FIRAuthErrorCodeRequiresRecentLogin - Updating email is a security sensitive operation that requires a recent login from the user. This error indicates the user has not signed in recently enough. To resolve, reauthenticate the user by invoking reauthenticateWithCredential:completion: on FIRUser.

有关所有FIRUser操作共有的错误代码列表,请参见@c FIRAuthErrors. */

See @c FIRAuthErrors for a list of error codes that are common to all FIRUser operations. */

长话短说,如果收到的 err 为零,那么您当前的帐户不仅会被删除,还会自动注销,但是您需要处理其他<文档中所述的strong> FIRAuthErrors

So long story short if the err received is nil your current users's account has not only been deleted but also signed out automatically, But you will need to handle other FIRAuthErrors as stated in the documentation

这篇关于从Firebase中删除帐户是否会自动注销用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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