How can I determine if a user has been removed from Firebase auth?

Two applications are in the same Firebase project. One application removed a user from Firebase Auth. But another application is still getting a user uid from somewhere, possibly a cache, and is also accessing data in a Firebase database using Auth uid. I mean, I can still get "user.uid" with let user = FIRAuth.auth().currentUserif you save the input.

In applications installed FIRDatabase.database().persistenceEnabled = true.

I would like to sing or update the cache in all applications if the user has been removed from Auth accordingly.

+4
source share
2 answers

, 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:

:

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

:

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

, , Auth firebase. , , .

+6

Firebase 4.0 :

func checkUserAgainstDatabase(completion: @escaping (_ success: Bool, _ error: NSError?) -> Void) {
    guard let currentUser = Auth.auth().currentUser else { return }
    currentUser.getIDTokenForcingRefresh(true, completion:  { (idToken, error) in
      if let error = error {
        completion(false, error as NSError?)
        print(error.localizedDescription)
      } else {
        completion(true, nil)
      }
    })
  }
0

Source: https://habr.com/ru/post/1658880/


All Articles