Last active
January 28, 2019 12:50
-
-
Save melvinkcx/060c6a084fd22895317a6dab8d88d1d9 to your computer and use it in GitHub Desktop.
Firebase Auth Using Facebook In Expo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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