Skip to content

Commit 4889dce

Browse files
feat: remove createAuth0Client, keep client prop only
1 parent 7d33191 commit 4889dce

File tree

4 files changed

+4
-43
lines changed

4 files changed

+4
-43
lines changed

EXAMPLES.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,13 @@ export default Posts;
105105

106106
## Use Auth0 outside of React
107107

108-
If you need to share an `Auth0Client` instance between the React tree and code that has no access to React's lifecycle — such as TanStack Start client function middleware — use `createAuth0Client` to create a shared instance and pass it to `Auth0Provider` via the `client` prop.
109-
110-
Using `createAuth0Client` ensures the `auth0-react` telemetry header is set correctly on the client.
108+
If you need to share an `Auth0Client` instance between the React tree and code that has no access to React's lifecycle — such as TanStack Start client function middleware — create an `Auth0Client` and pass it to `Auth0Provider` via the `client` prop.
111109

112110
```jsx
113111
// auth0-client.js
114-
import { createAuth0Client } from '@auth0/auth0-react';
112+
import { Auth0Client } from '@auth0/auth0-react';
115113

116-
export const auth0Client = createAuth0Client({
114+
export const auth0Client = new Auth0Client({
117115
domain: 'YOUR_AUTH0_DOMAIN',
118116
clientId: 'YOUR_AUTH0_CLIENT_ID',
119117
authorizationParams: {

__tests__/auth-provider.test.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import '@testing-library/jest-dom';
77
import { act, render, renderHook, screen, waitFor } from '@testing-library/react';
88
import React, { StrictMode, useContext } from 'react';
99
import pkg from '../package.json';
10-
import { Auth0Provider, Auth0ProviderOptions, createAuth0Client, useAuth0 } from '../src';
10+
import { Auth0Provider, Auth0ProviderOptions, useAuth0 } from '../src';
1111
import Auth0Context, {
1212
Auth0ContextInterface,
1313
initialContext,
@@ -143,18 +143,6 @@ describe('Auth0Provider', () => {
143143
});
144144
});
145145

146-
it('should inject auth0-react telemetry when using createAuth0Client', async () => {
147-
createAuth0Client({ clientId: 'foo', domain: 'bar' });
148-
expect(Auth0Client).toHaveBeenCalledWith(
149-
expect.objectContaining({
150-
auth0Client: {
151-
name: 'auth0-react',
152-
version: pkg.version,
153-
},
154-
})
155-
);
156-
});
157-
158146
it('should warn when client prop is used alongside domain or clientId', async () => {
159147
const warn = jest.spyOn(console, 'warn').mockImplementation(() => undefined);
160148
const wrapper = createWrapper({ client: clientMock, domain: 'foo', clientId: 'bar' } as unknown as Partial<Auth0ProviderOptions>);

src/auth0-provider.tsx

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ export type Auth0ProviderWithConfigOptions<TUser extends User = User> =
105105

106106
/**
107107
* Options for `Auth0Provider` when supplying a pre-configured `Auth0Client` instance.
108-
* Use `createAuth0Client` to create the client so telemetry is set correctly.
109108
*/
110109
export type Auth0ProviderWithClientOptions<TUser extends User = User> =
111110
Auth0ProviderBaseOptions<TUser> & { client: Auth0Client };
@@ -143,29 +142,6 @@ const toAuth0ClientOptions = (
143142
};
144143
};
145144

146-
/**
147-
* Creates a new `Auth0Client` with the `auth0-react` SDK telemetry header set.
148-
*
149-
* Use this when you need to share a single client instance with `Auth0Provider`
150-
* and also access Auth0 outside of React (e.g. in TanStack Start client function middleware).
151-
*
152-
* @example
153-
* ```tsx
154-
* const client = createAuth0Client({ domain, clientId });
155-
*
156-
* // Use outside React (e.g. in TanStack Start client function middleware)
157-
* const token = await client.getTokenSilently();
158-
*
159-
* // Use inside React
160-
* function App() {
161-
* return <Auth0Provider client={client}><MyApp /></Auth0Provider>;
162-
* }
163-
* ```
164-
*/
165-
export const createAuth0Client = (options: Auth0ClientOptions): Auth0Client => {
166-
return new Auth0Client(toAuth0ClientOptions(options));
167-
};
168-
169145
/**
170146
* @ignore
171147
*/

src/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export {
55
Auth0ProviderWithClientOptions,
66
AppState,
77
ConnectedAccount,
8-
createAuth0Client,
98
} from './auth0-provider';
109
export { default as useAuth0 } from './use-auth0';
1110
export { default as withAuth0, WithAuth0Props } from './with-auth0';

0 commit comments

Comments
 (0)