Handle Cancel button in FirebaseUI auth page

孤街醉人 提交于 2020-03-05 04:37:52

问题


I use FirebaseUI prebuilt authentication for my swift project. I have two pages/controllers: main and user profile. I have created a navigation controller. When the user profile button is clicked, the login controller will be pushed to the navigation stack.

    let loginController = SignInController()
    self.navigationController?.pushViewController(loginController, animated: true)

Within the login controller, Firebase UI will be called and popped out from the navigation stack after the login is finished.

    DispatchQueue.main.async {
      let authVC = authUI.authViewController()
      authVC.modalPresentationStyle = .fullScreen
      self.present(authVC, animated: true, completion: nil)
      self.navigationController?.popViewController(animated: true)}

However, there is a cancel button on the log-in page. I know how to hide it, yet I think a better logic would be returning back to the home page when this button is pressed. The FirebaseUI's documentation doesn't cover how to handle the cancel button.

My first thought was to set the rootController back to the main page controller if the cancel button is pressed. Yet, obviously, if I call it right after the Auth page is present, the App will go back to the home page without waiting for the user to finish sign-in/sign up

    DispatchQueue.main.async {
      let authVC = authUI.authViewController()
      authVC.modalPresentationStyle = .fullScreen
      self.present(authVC, animated: true, completion: nil)
      appDelegate?.window.rootController = mainController()

I've also tried to clear the navigation stack, yet it didn't work

Sorry, new to Swift. Any thoughts/advice/suggestions are greatly appreciated.

来源:https://stackoverflow.com/questions/60425050/handle-cancel-button-in-firebaseui-auth-page

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