Search code examples
react-nativefacebook-ios-sdk

How does the Facebook SDK for React-Native maintain login informations?


I installed the FBSDK into my React-Native application.

The login works and I can get user data via the Graph API right after the login, but everything going on is a mystery to me.

How does it maintain the login information? Like, when I restart the app and would like to make a Graph API request or share things, without showing the login dialog again?


Solution

  • If I'm not mistaken react-native-fbsdk maintains the login information in a token via AccessToken.getCurrentAccessToken(). Its whereabouts are likely platform specific but don't quote me on that.

    Assuming you've asked for enough permissions at login, all subsequent Graph API requests shouldn't trigger any additional popups. These can be make as follows:

    // Create a graph request asking for user information with a callback to handle the response.
    const infoRequest = new GraphRequest(
      '/me',
      null,
      this._responseInfoCallback,
    );
    // Start the graph request.
    new GraphRequestManager().addRequest(infoRequest).start();
    

    Full example at: https://github.com/facebook/react-native-fbsdk#graph-api

    If you after about sharing, you'll likely need extra permissions (publish_actions) that need to be explicitly granted beforehand. These can be asked at first login but may not gone through Facebook's approval process as that's against their best practices that ask to only ask for the permissions we need and to ask for them in context.

    This is where Login Manager comes very handy as it lets you request additional permissions as users progress through the app, but this is at the cost of extra popups.