如何检测用户是否已从Firebase身份验证中删除? [英] How can I detect if the user was deleted from Firebase auth?

查看:80
本文介绍了如何检测用户是否已从Firebase身份验证中删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两个应用程序在同一个Firebase项目中.一个应用从Firebase身份验证中删除了一个用户.但是另一个应用仍然可以从某个地方(可能是缓存)获取用户uid,并且也可以使用Auth的uid访问Firebase数据库中的数据. 我的意思是,如果保持登录状态,我仍然可以通过let user = FIRAuth.auth().currentUser来获取"user.uid".

Two apps are in the same Firebase project. One app deleted a user from Firebase Auth. But another app still get user uid from somewhere, maybe cache, and access the data in Firebase database with Auth's uid too. I mean I can still get "user.uid" by let user = FIRAuth.auth().currentUser, if keeping sign-in.

这两个应用都设置了FIRDatabase.database().persistenceEnabled = true.

如果相应地从Auth中删除了用户,我想在所有应用程序中显示或刷新缓存.

I would like to sing out or refresh cache at all apps if the user was deleted from Auth accordingly.

推荐答案

您可以在appDelegate内执行此操作:

You can achieve it by doing this inside appDelegate:

//Check if user does exists
    func checkUserAgainstDatabase(completion: @escaping (_ success: Bool, _ error: NSError?) -> Void) {
        guard let currentUser = FIRAuth.auth()?.currentUser else { return }
        currentUser.getTokenForcingRefresh(true) { (idToken, error) in
            if let error = error {
                completion(false, error as NSError?)
                print(error.localizedDescription)
            } else {
                completion(true, nil)
            }
        }
    }

使用didFinishLaunchingWithOptions中的上述功能检查后,您可以执行以下操作:

And you can do something like this after checking with the above function in didFinishLaunchingWithOptions:

如果用户确实存在:

self.window?.rootViewController = self.storyboard?.instantiateViewController(withIdentifier: "CustomTabBarViewController")

其他:

self.window?.rootViewController = self.storyboard?.instantiateViewController(withIdentifier: "WelcomeViewController")

要测试它是否有效,只需从firebase的Auth管理器中手动删除用户即可.因此,如果用户已被删除,它应该只显示welcoome屏幕.

And to test if it did work simply remove user manually from the Auth manager from firebase. So like this it should just show the welcoome screen if user has been deleted.

这篇关于如何检测用户是否已从Firebase身份验证中删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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