Skip to content

Auth0ContextInterface has incorrect interface typing #1334

@nairb774

Description

@nairb774

Checklist

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis points to a verified bug in the codeneeds investigationAn issue that has more questions to answer or otherwise needs work to fully understand the issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions