I am trying to Handling user authentication state changes and assign root view controller not working?

50 Views Asked by At

I am trying to Handling user authentication state changes in Appdelegate.swift and assign the root view controller but it isn't work Note: already print the user Any help please

NotificationCenter.default.addObserver(forName: NSNotification.Name.AuthStateDidChange, object: Auth.auth(), queue: nil) { _ in
        Auth.auth().addStateDidChangeListener { (auth, user) in

            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            if user != nil {
                print(user?.displayName! as Any)

                let controller = storyboard.instantiateViewController(withIdentifier: "MainTabBarController") as? MainTabBarViewController
                self.window?.rootViewController = controller
                self.window?.makeKeyAndVisible()

            }else{



             let controller = storyboard.instantiateViewController(withIdentifier: "MenuViewController") as? MenuViewController
               self.window?.rootViewController = controller
              self.window?.makeKeyAndVisible()
            }
        }

    }
0

There are 0 best solutions below