Reputation: 1974
I have a react-native app created with Expo and m Firebase as the backend.
I have already done the Facebook login which gives me the facebook token
Now that I have gotten the facebook token, I am trying to integrate my app to use Firebase (so that i have the Firebase userid) which I am encountering difficulties
I searched online and only found the code for Google Oauth
googleAuthenticate = (idToken, accessToken) => {
const credential = firebase.auth.GoogleAuthProvider.credential(idToken, accessToken);
return firebase.auth().signInWithCredential(credential);
};
Anyone can share how they integrate facebook oauth with firebase together with Expo? Thanks
Upvotes: 0
Views: 927
Reputation: 2781
Here is code for auth from Facebook and google.
Facebook Code:
LoginManager
.logInWithReadPermissions(['public_profile', 'email'])
.then((result) => {
if (!result.isCancelled) {
console.log(`Login success with permissions: ${result.grantedPermissions.toString()}`)
// get the access token
return AccessToken.getCurrentAccessToken()
}
})
.then(data => {
if (data) {
// create a new firebase credential with the token
const credential = firebase.auth.FacebookAuthProvider.credential(data.accessToken)
// login with credential
return firebase.auth().signInWithCredential(credential)
}
})
.then((currentUser) => {
if (currentUser) {
//Here is user profile
}
}
Google Code:
GoogleSignin.configure()
.then(() => {
GoogleSignin.signIn()
.then((data) => {
// create a new firebase credential with the token
const credential = firebase.auth.GoogleAuthProvider.credential(data.idToken, data.accessToken)
// login with credential
return firebase.auth().signInWithCredential(credential)
})
.then((currentUser) => {
//Here is user profile
}
And this is simple login code:
firebase.auth().signInWithEmailAndPassword(this.state.username, this.state.password)
.then((user) => {
//Here is user profile after login
}
Thanks and let me know if need more!!
Upvotes: 3