Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 14 commits into from
Aug 18, 2022
Merged

Conversation

stevehobbsdev
Copy link
Contributor

@stevehobbsdev stevehobbsdev commented Aug 12, 2022

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

Screen.Recording.2022-08-12.at.13.29.50.mov

Testing

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

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

Checklist

@stevehobbsdev stevehobbsdev requested a review from a team as a code owner August 12, 2022 12:33
@stevehobbsdev stevehobbsdev added the medium This PR may require moderate effort to action, or contains many changes to review label Aug 12, 2022
Copy link
Contributor

@adamjmcgrath adamjmcgrath left a comment

Choose a reason for hiding this comment

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

lgtm, couple of little things

src/hooks/auth0-provider.js Outdated Show resolved Hide resolved
src/hooks/auth0-provider.js Outdated Show resolved Hide resolved
src/hooks/auth0-provider.js Show resolved Hide resolved
Steve Hobbs and others added 2 commits August 16, 2022 13:21
adamjmcgrath
adamjmcgrath previously approved these changes Aug 16, 2022
@@ -0,0 +1,32 @@
export const idTokenNonProfileClaims = new Set([
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any source we used to get these? Probably we should add the source as a comment here for future reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm using the same list as defined internally in SPA JS: https://github.com/auth0/auth0-spa-js/blob/master/src/jwt.ts#L6

@stevehobbsdev stevehobbsdev merged commit f383319 into vnext Aug 18, 2022
@stevehobbsdev stevehobbsdev deleted the feat/hooks branch August 18, 2022 11:24
@poovamraj poovamraj mentioned this pull request Sep 9, 2022
@poovamraj poovamraj mentioned this pull request Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium This PR may require moderate effort to action, or contains many changes to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants