Would FirebaseAuth return my current user for Widget and IntentExtension while having the main project as React native?

Viewed 43

I am currently creating a WidgetKit for my React Native application. However, I need to create a post request to retrieve my current logined user information. I was wondering if importing FirebaseAuth in my WidgetKit would return the correct current user in my widget project?

import FirebaseAuth

func getUser(){
    FIRAuth.auth().currentUser?.uid
}
1 Answers

I wouldn't recommend requiring actual Firebase functionality in a WidgetExtension unless your Widget requires data that may change. If it really does, you should just be including your Firebase code in the build for the Widget, you don't want to duplicate the code you've written for interacting with Firebase. If you don't need live data, just save the Object your widget needs access to into the UserDefaults. You can do this easily so long as the object in question conforms to Codable. I'm assuming you're suggesting using FirebaseAuth because the Object you want to construct relies on your Firebase data in some way, but there's no need to actually interact with Firebase in a Widget. The log in status of your user can't change if they aren't in your app, so it's not particularly unsafe to save the data directly. If they sign out you can just clear the UserDefaults value.

Related