How to check if user has valid Auth Session Firebase iOS?

前端 未结 7 2246
生来不讨喜
生来不讨喜 2021-02-19 04:53

I wanna check if the user has still a valid session, before I present the Home View controller of my app. I use the latest Firebase API. I think if I use the legacy, I\'ll be ab

7条回答
  •  梦毁少年i
    2021-02-19 05:45

    Solution in Swift 4

    override func viewDidLoad() {
        super.viewDidLoad()
        setupLoadingControllerUI()
        checkIfUserIsSignedIn()
    }
    
    private func checkIfUserIsSignedIn() {
    
        Auth.auth().addStateDidChangeListener { (auth, user) in
            if user != nil {
                // user is signed in
                // go to feature controller 
            } else {
                 // user is not signed in
                 // go to login controller
            }
        }
    }
    

提交回复
热议问题