getCredentials usage react native sdk

Hello,

I have successfully implemented the auth0 biometric flow with Webauthn and token rotation using the react-native-auth0.

Currently I use the provider for authorize user to connect. After that I would like to use the getCredentials method outside a react component.

I use this code in my middleware:

const baseQuery = fetchBaseQuery({
  timeout: 12000,
  prepareHeaders: async headers => {
    const userAgent = UserAgent.getUserAgent();

    const credentials = await auth0Instance.credentialsManager.getCredentials(
      AUTH0_SCOPE,
      AUTH0_TOKEN_MIN_TLL,
    );

    if (credentials.accessToken) {
      headers.set('Authorization', `Bearer ${credentials.accessToken}`);
    }

    headers.set('Accept', 'application/json');
    headers.set('User-Agent', userAgent);

    return headers;
  },
});

The problem is that auth0Instance is not the instance created by the Auth0Provider. Is there any solution to use the function getCredentials use by the provider outside a react component ? Or should I consider another strategy to refresh the token, if so waht could be this strategy ?

I use the version 4 SDK

Hi @jerembardon,

Welcome to the Auth0 Community!

The getCredentials method is the correct approach here to get the access token.

In this case, you might need to export an instance of your Auth0Client for use outside of a React component.

I hope this helps!

Let me know if you have any questions.

Thank you,
Rueben

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.