Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Add method to listen for changes to the access token #666

Merged

Conversation

matt-oakes
Copy link
Contributor

This PR adds a method which allows you to monitor the access token for changes. This enable you to have a hook which accurately represents the Facebook Access Token which will update when the user logs in or out.

It is implemented using the notifications (iOS) and tracker (Android) which the natvie Facebook SDKs provide.

Test Plan:

Tested on both platforms using the following hook code:

const useFacebookToken = () => {
  const [accessToken, setAccessToken] = React.useState<FBSDK.AccessToken>();

  React.useEffect(() => {
    FBSDK.AccessToken.getCurrentAccessToken().then(setAccessToken);

    return FBSDK.AccessToken.addListener(setAccessToken);
  }, []);

  return accessToken;
};

@matt-oakes
Copy link
Contributor Author

For anyone who wants to install and try this now, you can install it using this:

yarn add react-native-fbsdk@https://github.com/matt-oakes/react-native-fbsdk.git#access-token-listener

or:

npm install --save react-native-fbsdk@https://github.com/matt-oakes/react-native-fbsdk.git#access-token-listener

ps. Loving the PR number I ended up with! 😈

Copy link
Contributor

@janicduplessis janicduplessis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @matt-oakes !

@janicduplessis janicduplessis merged commit 26278c9 into facebookarchive:master Nov 7, 2019
@matt-oakes matt-oakes deleted the access-token-listener branch March 1, 2020 13:40
@matt-oakes matt-oakes restored the access-token-listener branch March 1, 2020 13:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants