Skip to content

Commit 8cd90ef

Browse files
fix: warn when client prop is used with domain/clientId
1 parent f660867 commit 8cd90ef

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

__tests__/auth-provider.test.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,31 @@ describe('Auth0Provider', () => {
155155
);
156156
});
157157

158+
it('should warn when client prop is used alongside domain or clientId', async () => {
159+
const warn = jest.spyOn(console, 'warn').mockImplementation(() => undefined);
160+
const wrapper = createWrapper({ client: clientMock, domain: 'foo', clientId: 'bar' } as any);
161+
renderHook(() => useContext(Auth0Context), { wrapper });
162+
await waitFor(() => {
163+
expect(warn).toHaveBeenCalledWith(
164+
expect.stringContaining('the `client` prop takes precedence')
165+
);
166+
});
167+
warn.mockRestore();
168+
});
169+
170+
it('should not warn when only client prop is provided', async () => {
171+
const warn = jest.spyOn(console, 'warn').mockImplementation(() => undefined);
172+
const wrapper = createWrapper({ client: clientMock });
173+
renderHook(() => useContext(Auth0Context), { wrapper });
174+
await waitFor(() => {
175+
expect(clientMock.checkSession).toHaveBeenCalled();
176+
});
177+
expect(warn).not.toHaveBeenCalledWith(
178+
expect.stringContaining('the `client` prop takes precedence')
179+
);
180+
warn.mockRestore();
181+
});
182+
158183
it('should check session when logged out', async () => {
159184
const wrapper = createWrapper();
160185
const { result } = renderHook(

src/auth0-provider.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,13 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
198198
client: providedClient,
199199
...clientOpts
200200
} = opts as Auth0ProviderBaseOptions<TUser> & Auth0ClientOptions & { client?: Auth0Client };
201+
if (providedClient && (clientOpts.domain || clientOpts.clientId)) {
202+
console.warn(
203+
'Auth0Provider: the `client` prop takes precedence over `domain`/`clientId` and other ' +
204+
'configuration options. Remove `domain`, `clientId`, and any other Auth0Client configuration ' +
205+
'props when using the `client` prop.'
206+
);
207+
}
201208
const [client] = useState(
202209
() => providedClient ?? new Auth0Client(toAuth0ClientOptions(clientOpts))
203210
);

0 commit comments

Comments
 (0)