-
Notifications
You must be signed in to change notification settings - Fork 231
Description
Checklist
- The issue can be reproduced in the react-native-auth0 sample app (or N/A).
- I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
- I have looked into the API documentation and have not found a suitable solution or answer.
- I have searched the issues and have not found a suitable solution or answer.
- I have searched the Auth0 Community forums and have not found a suitable solution or answer.
- I agree to the terms within the Auth0 Code of Conduct.
Description
Some of the types on Auth0ContextInterface don't seem to match the implementation as well as the examples. This is triggering lint messages for https://typescript-eslint.io/rules/unbound-method/ when used following examples.
Take getCredentials as an example:
react-native-auth0/src/hooks/Auth0Context.ts
Lines 75 to 80 in 92b3637
| getCredentials( | |
| scope?: string, | |
| minTtl?: number, | |
| parameters?: Record<string, unknown>, | |
| forceRefresh?: boolean | |
| ): Promise<Credentials>; |
The way that function's type is written implies that getCredentials is a member of a class that makes use of this internally. Because of that, writing code like const { getCredentials } = useAuth0(); getCredentials(); will fail because the this parameter isn't being set properly. Example of where that lint would fail:
| const { user, getCredentials } = useAuth0(); |
Contrast that with the type for clearCredentials:
| clearCredentials: () => Promise<void>; |
That is saying that the property is a function which doesn't need a bound this and will work with a destructuring assignment.
Looking at the implementation, many of the properties of the Auth0ContextInterface interface likely should be written similar to clearCredentials. In the case of getCredentials it would likely look something like the following. Note the : after the name and the change to => in the type specification:
getCredentials: (
scope?: string,
minTtl?: number,
parameters?: Record<string, unknown>,
forceRefresh?: boolean
) => Promise<Credentials>;
Reproduction
- Configure typescript-eslint (8.44.1) with the referenced lint enabled with the default settings.
- Run over the linter over the examples in the repo.
Additional context
No response
react-native-auth0 version
5.0.0-beta.6
React Native version
0.79.2
Expo version
53.0.22
Platform
iOS
Platform version(s)
All