React-native-firebase: Export User Flow type

Created on 20 Dec 2017  路  2Comments  路  Source: invertase/react-native-firebase

Issue

I created a function to loginOrRegister from facebook login.
To add a Flow return type to its method signature, I would need the User type to be exported.
I am not sure how it has to be done (export User class from _dist/index.js_ ?, export an interface?, export a type?) but I would be happy to contribute if someone could give details.

_See Promise<User> in return type of function below._

export default function loginOrRegister(): Promise<User> {
  const permissions = ['public_profile', 'email'];

  return LoginManager.logInWithReadPermissions(permissions)
    .then(result => {
      if (result.isCancelled) {
        return Promise.reject(new Error('The user cancelled the request'));
      }
      return AccessToken.getCurrentAccessToken();
    })
    .then(data => {
      if (!data) {
        return Promise.reject(
          new Error("facebook-auth: couldn't get current access token")
        );
      }
      const credential = firebase.auth.FacebookAuthProvider.credential(
        data.accessToken
      );
      return firebase.auth().signInWithCredential(credential);
    })
    .catch(error => {
      const { code, message } = error;
      logging.recordError({
        domain: 'Facebook Login error',
        message,
        code
      });
      return Promise.reject(error);
    });
}

Environment

  1. Application Target Platform: Both
  2. Development Operating System: macOS Sierra
  3. React Native version: ^0.49.5
  4. RNFirebase Version: ^3.1.1
  5. Firebase Module: auth
Typings

Most helpful comment

@fdnhkj This will be fixed in the next release. You'll be able to do:

import type { User } from 'react-native-firebase';

All 2 comments

@fdnhkj Thanks, we're aware of this and haven't quite figured out the best approach yet either! We're open to suggestions...

@fdnhkj This will be fixed in the next release. You'll be able to do:

import type { User } from 'react-native-firebase';
Was this page helpful?
0 / 5 - 0 ratings