Skip to content

Commit 463a4ce

Browse files
fix: export named sub-types to resolve Omit incompatibility with union type
1 parent f013445 commit 463a4ce

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

examples/cra-react-router/src/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { createRoot } from "react-dom/client";
22
import React, { PropsWithChildren } from 'react';
33
import App from './App';
4-
import { Auth0Provider, AppState, Auth0ProviderOptions, User } from '../../../src/index.js';
4+
import { Auth0Provider, AppState, Auth0ContextInterface, User } from '@auth0/auth0-react';
55
import { BrowserRouter, useNavigate } from 'react-router-dom';
6+
import { Auth0ProviderWithConfigOptions } from '../../../src/index.js';
67

78
const Auth0ProviderWithRedirectCallback = ({
89
children,
910
context,
1011
...props
11-
}: PropsWithChildren<Auth0ProviderOptions>) => {
12+
}: PropsWithChildren<Omit<Auth0ProviderWithConfigOptions, 'context'>> & {
13+
context?: React.Context<Auth0ContextInterface<User>>
14+
}) => {
1215
const navigate = useNavigate();
1316

1417
const onRedirectCallback = (appState?: AppState, user?: User) => {

src/auth0-provider.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,29 @@ type Auth0ProviderBaseOptions<TUser extends User = User> = {
9696
context?: React.Context<Auth0ContextInterface<TUser>>;
9797
};
9898

99+
/**
100+
* Options for `Auth0Provider` when configuring Auth0 via `domain` and `clientId`.
101+
* Use this type when building wrapper components around `Auth0Provider`.
102+
*/
103+
export type Auth0ProviderWithConfigOptions<TUser extends User = User> =
104+
Auth0ProviderBaseOptions<TUser> & Auth0ClientOptions & { client?: never };
105+
106+
/**
107+
* Options for `Auth0Provider` when supplying a pre-configured `Auth0Client` instance.
108+
* Use `createAuth0Client` to create the client so telemetry is set correctly.
109+
*/
110+
export type Auth0ProviderWithClientOptions<TUser extends User = User> =
111+
Auth0ProviderBaseOptions<TUser> & Partial<Auth0ClientOptions> & { client: Auth0Client };
112+
99113
/**
100114
* The main configuration to instantiate the `Auth0Provider`.
101115
*
102-
* Either provide `domain` and `clientId` to have the provider create an `Auth0Client` internally,
103-
* or provide a pre-configured `client` instance created with `createAuth0Client`.
116+
* Either provide `domain` and `clientId` (`Auth0ProviderWithConfigOptions`)
117+
* or a pre-configured `client` instance (`Auth0ProviderWithClientOptions`).
104118
*/
105119
export type Auth0ProviderOptions<TUser extends User = User> =
106-
| (Auth0ProviderBaseOptions<TUser> & Auth0ClientOptions & { client?: never })
107-
| (Auth0ProviderBaseOptions<TUser> & Partial<Auth0ClientOptions> & { client: Auth0Client });
120+
| Auth0ProviderWithConfigOptions<TUser>
121+
| Auth0ProviderWithClientOptions<TUser>;
108122

109123
/**
110124
* Replaced by the package version at build time.

src/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export {
22
default as Auth0Provider,
33
Auth0ProviderOptions,
4+
Auth0ProviderWithConfigOptions,
5+
Auth0ProviderWithClientOptions,
46
AppState,
57
ConnectedAccount,
68
createAuth0Client,

0 commit comments

Comments
 (0)