0.3.4 • Published 6 years ago

react-native-firebase-auth-hoc v0.3.4

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Auth HOC

Usage

import React from 'react';
import { TouchableOpacity, View, Text } from 'react-native';
import withAuth, { Provider as AuthProvider } from 'react-native-firebase-auth-hoc';

function Home({ auth }) {
  return (
    <View
      style={{
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center'
      }}
    >
      <Text>{JSON.stringify(auth.user)}</Text>
    </View>
  );
}

const HomeWithHOC = withAuth(Home, {
  style: {
    backgroundColor: '#fdfdfd'
  },
  buttonStyle: {
    backgroundColor: 'lightblue'
  }
});

class App extends React.Component {
  render() {
    return (
      <AuthProvider
        onInit={uid =>
          new Promise(r => {
            setTimeout(() => {
              r({ age: 30, gender: 'male' });
            }, 500);
          })
        }
      >
        <HomeWithHOC />
      </AuthProvider>
    );
  }
}

export default App;

Provider

Reference

Props

propertydescription
onInitFunctions executed at initialization and updating of custom user information.

onInit

NAMETYPEREQUIREDDESCRIPTION
promisePromiseYesPromise to return user information to add.

withAuth

Reference

Options

withAuth((Component: React.ComponentClass<any>), (options: Options = initialOptions));
emailConfig?: {
  title?: string;
  style?: {};
  textStyle?: {};
  renderButton?: Button;
} | null;
anonymousConfig?: {
  title?: string;
  style?: {};
  textStyle?: {};
  renderButton?: Button;
} | null;
facebookConfig?: {
  title?: string;
  style?: {};
  textStyle?: {};
  getToken: () => Promise<any>;
  renderButton?: Button;
};
googleConfig?: {
  title?: string;
  style?: {};
  textStyle?: {};
  getToken: () => Promise<any>;
  renderButton?: Button;
};
logoConfig?: {
  title?: string;
  style?: {};
  renderLogo?: () => Element;
};
initializerConfig?: {
  text?: string;
  style?: {};
  duration?: number;
  renderInitializer?: () => Element;
};
renderLoginBackScreen?: () => Element;
style?: {};

Property

propertydescription
userfirebase.user

Methods

methodsdescription
signInChange to login status.
signOutChange to logout status.
signInAnonymouslyAsynchronously signs in as an anonymous user.
signInWithFacebookYou can log in to Facebook via a promise function that returns a token.
signInWithGoogleYou can log in to Google via a promise function that returns a token.
createUserWithEmailAndPasswordAsynchronously signs in using an email and password.

signIn()

signIn();

signOut()

signOut();

signInAnonymously()

signInAnonymously();

signInWithFacebook()

signInWithFacebook: (promise: () => Promise<string>) => Promise<any>;
NAMETYPEREQUIREDDESCRIPTION
promisePromiseYesPromise to return a Facebook token
async function getExpoFacebookToken() {
  const response = await Expo.Facebook.logInWithReadPermissionsAsync(FACEBOOK_APP_ID, {
    permissions: ['public_profile', 'email'],
    behavior: 'web'
  });

  if (response.type === 'success') {
    return response.token;
  } else {
    throw new Error('Expo Error');
  }
}

signInWithFacebook(getExpoFacebookToken);

signInWithGoogle()

signInWithGoogle: (promise: () => Promise<string>) => Promise<any>;
NAMETYPEREQUIREDDESCRIPTION
promisePromiseYesPromise to return a Google token
async function getExpoGoogleToken() {
  const response = await Expo.Google.logInAsync({
    androidClientId: YOUR_CLIENT_ID_HERE,
    iosClientId: YOUR_CLIENT_ID_HERE,
    scopes: ['profile', 'email']
  });

  if (response.type === 'success') {
    return response.accessToken;
  } else {
    throw new Error('Expo Error');
  }
}

signInWithGoogle(getExpoGoogleToken);

createUserWithEmailAndPassword()

createUserWithEmailAndPassword: (email: string, password: string) => Promise<any>;
NAMETYPEREQUIREDDESCRIPTION
emailstringYesemail
passwordstringYespassword

Support

react-navigation

withAuth(createBottomTabNavigator({
  Home: HomeScreen,
  Settings: SettingsScreen,
});

// Home, Settings -> screenProps.auth
0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago