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

Add TUser type param to useAuth0 hook #230

Merged
merged 4 commits into from
Apr 16, 2021
Merged

Add TUser type param to useAuth0 hook #230

merged 4 commits into from
Apr 16, 2021

Conversation

Jameskmonger
Copy link
Contributor

@Jameskmonger Jameskmonger commented Apr 15, 2021

Description

Adds generic type parameter to useAuth0 to specify type of user (see #228 for feature request)

const { user } = useAuth0<{ name: string; }>();

user.name // string

This parameter is optional and will use the already existing User type if not provided

References

Closes #228
Closes #201

Testing

I tried to unit test this but I'm not sure of the correct way to pass type params to a hook through renderHook

You can see this in-use in the Create React App example

  • This change adds test coverage for new/changed/fixed functionality

Checklist

  • I have added documentation for new/changed functionality in this PR or in auth0.com/docs
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not master

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

README.md Outdated
@@ -77,7 +77,7 @@ function App() {
user,
loginWithRedirect,
logout,
} = useAuth0();
} = useAuth0<{ name: string }>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
} = useAuth0<{ name: string }>();
} = useAuth0();

The README examples are plain js

@adamjmcgrath adamjmcgrath merged commit f58d5b6 into auth0:master Apr 16, 2021
@adamjmcgrath
Copy link
Contributor

Thanks @Jameskmonger!

@Jameskmonger
Copy link
Contributor Author

Thanks for merging @adamjmcgrath 😄

@adamjmcgrath adamjmcgrath mentioned this pull request May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow generic typing on useAuth0 hook to extend User Improve accuracy of AuthState type definitions
2 participants