react-native-auth0 icon indicating copy to clipboard operation
react-native-auth0 copied to clipboard

[SDK-3591] New Hook API supporting login and logout

Open stevehobbsdev opened this issue 3 years ago • 0 comments

Changes

This PR adds a new hook useAuth0 (based on Auth0 React's hook of the same name) as an alternative to using the Auth0 class, useful for when using function components.

Example:

const onLogin = async () => {
    try {
      const credentials = await authorize({scope: 'openid profile email'});

      Alert.alert('AccessToken: ' + credentials.accessToken);
      setAccessToken(credentials.accessToken);
    } catch (e) {
      console.log(e);
    }
};

Supports:

  • authorize - log in using the ULP
  • clearSession - log out
  • user - get the user profile
  • isLoading (not currently used but here for future development when the credentials manager is added)
  • error

Notes:

  • The Auth0 class was moved from the index file to a different file to fix an issue with cyclic imports
  • Upgrades to react@17 in dev dependencies
  • Upgrades to jest@28
  • API docs still to be added

Quickstart demo

https://user-images.githubusercontent.com/766403/184354283-ada855f9-fa23-4640-bfa9-c37e7f006837.mov

Testing

Unit tests have been added, as well as the API being tested using the quickstart (branch with changes).

  • [X] This change adds unit test coverage
  • [X] This change has been tested on the latest version of the platform/language or why not

Checklist

stevehobbsdev avatar Aug 12 '22 12:08 stevehobbsdev