Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 296
kinghenry14 Avatar asked Jun 12 '16 23:06

kinghenry14


1 Answers

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 {
           print(user)
        } else {
           print("Not signed in")
        }
    }
like image 97
Chris Avatar answered Nov 04 '22 15:11

Chris