react-native-auth0
react-native-auth0 copied to clipboard
[SDK-3591] New Hook API supporting login and logout
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 ULPclearSession- log outuser- get the user profileisLoading(not currently used but here for future development when the credentials manager is added)error
Notes:
- The
Auth0class was moved from theindexfile to a different file to fix an issue with cyclic imports - Upgrades to
react@17in 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
- [ ] I have read the Auth0 general contribution guidelines
- [ ] All existing and new tests complete without errors
- [ ] All active GitHub checks have passed