kinghenry14 kinghenry14 - 10 months ago 155
Swift Question

Accessing FIRUser in ViewController in iOS

I am using Firebase Authentication, and have been able to successfully login with facebook and google in the same iOS app in swift.

My issue is that the only place I seem to have access to the FIRUser class is from the AppDelegate.swift file where the auth info returns.

I can print the user email and other profile info into the console from the AppDelegate.swift file but I am not sure how to render this on the corresponding view through the view controller. It seems to be the same issue for both google and facebook. Anyone else know how to solve this?


You can access your current user anywhere you have imported Firebase this way: FIRAuth.auth()?.currentUser.

You can also add an auth state listener this way:

FIRAuth.auth()?.addStateDidChangeListener() { auth, user in
        if user != nil {
        } else {
           print("Not signed in")