title: Integrating FirebaseUI Auth in react native
body: <p>I've managed to (almost) integrate FirebaseUI Auth in to my react-native app in iOS. I can click on a react-native button, load the firebase auth flow, and send a callback to a react-native javascript function once logged in. I can call the function with the firebase user's UID or refreshToken.</p>
  
  <p>I'm stuck trying to make use of this in react native though. Is it possible to log in a user to firebase in react-native by using just a UID or the refresh token?</p>
  
  <p>EDIT: adding some of the code, though I'm sure it could use some refactoring unrelated to this problem:</p>
  
  <p>in ios folder</p>
  
  <h1>in AppDelegate.m</h1>
  
  <pre><code>FUIAuth *authUI;
  RCTResponseSenderBlock rnOnLogin;
  
  - (void)authUI:(FUIAuth *)authUI didSignInWithUser:(nullable FIRUser *)user error:(nullable NSError *)error {
    // Implement this method to handle signed in user or error if any.
     RCTLogInfo(@"Logged in (app delegate)");
    if (user == NULL) {
      RCTLogInfo(@"Null User");
    } else {
      RCTLogInfo(@"Got User (app delegate)");
      RCTLogInfo(user.uid);
      RCTLogInfo(user.providerData);
      // HERE I CAN PASS INFO ABOUT USER TO REACT NATIVE
      rnOnLogin(@[[NSNull null], user.providerData]);
    }
    if (error != NULL) {
      RCTLogInfo(@"Got Error  (app delegate)");
      RCTLogInfo(error);
    }
  }
  
  - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
  {
    RCTLogInfo(@"openURL application (app delegate)");
    return [[FUIAuth defaultAuthUI] handleOpenURL:url sourceApplication:sourceApplication];
  }
  </code></pre>
  
  <h1>in RCTFirebaseAuthUI.m</h1>
  
  <pre><code>@implementation RCTFirebaseAuthUI
  
  RCT_EXPORT_MODULE();
  
  UINavigationController *authViewController;
  extern FUIAuth *authUI;
  extern RCTResponseSenderBlock rnOnLogin;
  
  RCT_EXPORT_METHOD(showLogin:(nonnull RCTResponseSenderBlock )onLogin)
  {
    RCTLogInfo(@"showLogin method");
  
    if(authViewController == nil) {
     authViewController = [authUI authViewController];
     authViewController.delegate = authUI;
    }
  
    rnOnLogin = onLogin;
  
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UIViewController *rootViewController = window.rootViewController;
    [rootViewController presentViewController:authViewController animated:YES completion:nil];
  }
  </code></pre>
  
  <p>in react native</p>
  
  <h1>in ProfileScreen.js</h1>
  
  <pre><code>import * as firebase from 'firebase';
  
  export default class ProfileScreen extends Component {
  
    logout = () =&gt; {
      firebase.auth().signOut()
    }
  
    setUid = (error, token) =&gt; {
      console.log('rn')
      console.log(token)
  
      // HERE I NEED TO LOGIN THE USER TO REACT NATIVE's FIREBASE
      // firebase.auth().signInWithCredential(token).catch((error) =&gt;
      //  console.log(error)
      //)
    }
  
    pushLoginScreen = () =&gt; {
      var loginUI = NativeModules.FirebaseAuthUI
      loginUI.showLogin(this.setUid)
    }
  
    constructor(props) {
      super(props);
      this.state = {
        user: null
      };
      firebase.auth().onAuthStateChanged((user) =&gt; {
        this.setState({
          user: user
        })
      })
    }
  
    render() {
      console.log('render profile')
      console.log(this.state.user)
      let user = this.state.user
      if (user !== null) {
        return (
          &lt;View&gt;
             &lt;Text&gt;{user.email}&lt;/Text&gt;
          &lt;/View&gt;
        )
      } else {
        return (
          &lt;View&gt;
            &lt;Text&gt;Profile&lt;/Text&gt;
            &lt;Button title="Login" onPress={this.pushLoginScreen} /&gt;
          &lt;/View&gt;
        )
      }
    }
  }
  </code></pre>