Skip to content

Instantly share code, notes, and snippets.

@melvinkcx
Last active January 28, 2019 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melvinkcx/060c6a084fd22895317a6dab8d88d1d9 to your computer and use it in GitHub Desktop.
Save melvinkcx/060c6a084fd22895317a6dab8d88d1d9 to your computer and use it in GitHub Desktop.
Firebase Auth Using Facebook In Expo
// Say this is /utils/auth.js
import firebase from './firebase'
export async function signInWithFacebook() {
const appId = Expo.Constants.manifest.extra.facebook.appId;
const permissions = ['public_profile', 'email']; // Permissions required, consult Facebook docs
const {
type,
token,
} = await Expo.Facebook.logInWithReadPermissionsAsync(
appId,
{permissions}
);
switch (type) {
case 'success': {
await firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL); // Set persistent auth state
const credential = firebase.auth.FacebookAuthProvider.credential(token);
const facebookProfileData = await firebase.auth().signInAndRetrieveDataWithCredential(credential); // Sign in with Facebook credential
// Do something with Facebook profile data
// OR you have subscribed to auth state change, authStateChange handler will process the profile data
return Promise.resolve({type: 'success'});
}
case 'cancel': {
return Promise.reject({type: 'cancel'});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment