Reputation: 794
I'd like to sign users into my React-Native app using Parse and Facebook but it seems like the Facebook JS SDK is dependent on the dom. How can I sign in a user with facebook?
I'm currently using https://github.com/magus/react-native-facebook-login to log the user in natively, so I have access to their auth token, ect. But can't use the Parse.FacebookUtils.login() without the FB JS SDK.
Upvotes: 3
Views: 1390
Reputation: 6948
Parse.FacebookUtils.logIn
actually does not rely upon the FB JS SDK, so you can call it directly (as long as you pass in the authData
object).
In case it's helpful to anyone else, I ran into difficulties linking and unlinking Parse accounts with Facebook accounts. The unlink
method, for instance, relies on the FB JS SDK. I worked around this by 1. not calling Parse.FacebookUtils.init
, 2. creating a "fake Facebook provider":
var FakeFacebookProvider = {
getAuthType: function () {
return 'facebook';
},
restoreAuthentication: function () {
return true;
},
};
and 3. passing this in to Parse.User._isLinked
and Parse.User._unlinkFrom
:
if (user._isLinked(FakeFacebookProvider)) {
user._unlinkFrom(FakeFacebookProvider, {
So far this is working well. This would probably achieve the same thing as Tarrence's answer, without needing to edit the Parse code.
We really need a React Native compatible version of Parse.FacebookUtils
that doesn't rely on the FB JS SDK!
Upvotes: 0
Reputation: 314
If you have your authData from the native FB SDK, you can bypass the FacebookUtils.init() call entirely. This should log in to a Parse user with FB:
Parse.User._logInWith('facebook', {
authData: {
id: FB_USER_ID,
access_token: USER_ACCESS_TOKEN,
expiration_date: TOKEN_EXPIRATION_DATE
}
});
This'll return a Promise, same as Parse.FacebookUtils.logIn()
Upvotes: 6
Reputation: 794
I managed to get around this by commenting out the references to FB in the Parse SDK Parse.FacebookUtils.logIn flow and removing the safety checks. The FB SDK isn't actually needed to authenticate a user with Parse if you already have the authData object.
Obviously not an ideal solution, so leaving this open
Upvotes: 1
Reputation: 2086
In React Native, you can sign in an user with Facebook by making use of the RCTBridgeModule/NativeModules API.
In essence, you would have to write a native module that can directly access the native Facebook Login Manager API.
You can find more information about this process here.
Upvotes: 0