@auth0/auth0-react 1.10.2 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth0-context.d.ts +18 -0
- package/dist/auth0-context.d.ts.map +1 -1
- package/dist/auth0-provider.d.ts +21 -2
- package/dist/auth0-provider.d.ts.map +1 -1
- package/dist/auth0-react.cjs.js +40 -43
- package/dist/auth0-react.cjs.js.map +1 -1
- package/dist/auth0-react.esm.js +37 -41
- package/dist/auth0-react.esm.js.map +1 -1
- package/dist/auth0-react.js +40 -43
- package/dist/auth0-react.js.map +1 -1
- package/dist/auth0-react.min.js +2 -16
- package/dist/auth0-react.min.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/use-auth0.d.ts +2 -1
- package/dist/use-auth0.d.ts.map +1 -1
- package/dist/with-auth0.d.ts +5 -2
- package/dist/with-auth0.d.ts.map +1 -1
- package/dist/with-authentication-required.d.ts +7 -0
- package/dist/with-authentication-required.d.ts.map +1 -1
- package/package.json +5 -7
- package/src/auth0-context.tsx +4 -4
- package/src/auth0-provider.tsx +30 -9
- package/src/index.tsx +1 -0
- package/src/use-auth0.tsx +5 -3
- package/src/with-auth0.tsx +8 -4
- package/src/with-authentication-required.tsx +12 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { default as Auth0Provider, Auth0ProviderOptions, AppState, } from './aut
|
|
|
2
2
|
export { default as useAuth0 } from './use-auth0';
|
|
3
3
|
export { default as withAuth0, WithAuth0Props } from './with-auth0';
|
|
4
4
|
export { default as withAuthenticationRequired, WithAuthenticationRequiredOptions, } from './with-authentication-required';
|
|
5
|
-
export { default as Auth0Context, Auth0ContextInterface, RedirectLoginOptions, } from './auth0-context';
|
|
5
|
+
export { default as Auth0Context, Auth0ContextInterface, initialContext, RedirectLoginOptions, } from './auth0-context';
|
|
6
6
|
export { PopupLoginOptions, PopupConfigOptions, GetIdTokenClaimsOptions, GetTokenWithPopupOptions, LogoutOptions, LogoutUrlOptions, CacheLocation, GetTokenSilentlyOptions, IdToken, User, ICache, InMemoryCache, LocalStorageCache, Cacheable, } from '@auth0/auth0-spa-js';
|
|
7
7
|
export { OAuthError } from './errors';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,IAAI,aAAa,EACxB,oBAAoB,EACpB,QAAQ,GACT,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EACL,OAAO,IAAI,0BAA0B,EACrC,iCAAiC,GAClC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,OAAO,IAAI,YAAY,EACvB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,EACxB,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,uBAAuB,EACvB,OAAO,EACP,IAAI,EACJ,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,SAAS,GACV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,IAAI,aAAa,EACxB,oBAAoB,EACpB,QAAQ,GACT,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EACL,OAAO,IAAI,0BAA0B,EACrC,iCAAiC,GAClC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,OAAO,IAAI,YAAY,EACvB,qBAAqB,EACrB,cAAc,EACd,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,EACxB,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,uBAAuB,EACvB,OAAO,EACP,IAAI,EACJ,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,SAAS,GACV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/use-auth0.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { User } from '@auth0/auth0-spa-js';
|
|
2
3
|
import { Auth0ContextInterface } from './auth0-context';
|
|
3
4
|
/**
|
|
@@ -22,6 +23,6 @@ import { Auth0ContextInterface } from './auth0-context';
|
|
|
22
23
|
*
|
|
23
24
|
* TUser is an optional type param to provide a type to the `user` field.
|
|
24
25
|
*/
|
|
25
|
-
declare const useAuth0: <TUser extends User = User>() => Auth0ContextInterface<TUser>;
|
|
26
|
+
declare const useAuth0: <TUser extends User = User>(context?: import("react").Context<Auth0ContextInterface<User>>) => Auth0ContextInterface<TUser>;
|
|
26
27
|
export default useAuth0;
|
|
27
28
|
//# sourceMappingURL=use-auth0.d.ts.map
|
package/dist/use-auth0.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-auth0.d.ts","sourceRoot":"","sources":["../src/use-auth0.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAqB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,QAAA,MAAM,QAAQ
|
|
1
|
+
{"version":3,"file":"use-auth0.d.ts","sourceRoot":"","sources":["../src/use-auth0.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAqB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,QAAA,MAAM,QAAQ,6HAGuC,CAAC;AAEtD,eAAe,QAAQ,CAAC"}
|
package/dist/with-auth0.d.ts
CHANGED
|
@@ -19,8 +19,11 @@ export interface WithAuth0Props {
|
|
|
19
19
|
* export default withAuth0(MyComponent);
|
|
20
20
|
* ```
|
|
21
21
|
*
|
|
22
|
-
* Wrap your class components in this Higher Order Component to give them access to the Auth0Context
|
|
22
|
+
* Wrap your class components in this Higher Order Component to give them access to the Auth0Context.
|
|
23
|
+
*
|
|
24
|
+
* Providing a context as the second argument allows you to configure the Auth0Provider the Auth0Context
|
|
25
|
+
* should come from f you have multiple within your application.
|
|
23
26
|
*/
|
|
24
|
-
declare const withAuth0: <P extends WithAuth0Props>(Component: React.ComponentType<P
|
|
27
|
+
declare const withAuth0: <P extends WithAuth0Props>(Component: React.ComponentType<P>, context?: React.Context<Auth0ContextInterface<import("@auth0/auth0-spa-js").User>>) => React.ComponentType<Omit<P, "auth0">>;
|
|
25
28
|
export default withAuth0;
|
|
26
29
|
//# sourceMappingURL=with-auth0.d.ts.map
|
package/dist/with-auth0.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-auth0.d.ts","sourceRoot":"","sources":["../src/with-auth0.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAqB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,qBAAqB,CAAC;CAC9B;AAED
|
|
1
|
+
{"version":3,"file":"with-auth0.d.ts","sourceRoot":"","sources":["../src/with-auth0.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAqB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,qBAAqB,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,QAAA,MAAM,SAAS,4LAad,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { ComponentType, FC } from 'react';
|
|
2
2
|
import { RedirectLoginOptions, User } from '@auth0/auth0-spa-js';
|
|
3
|
+
import { Auth0ContextInterface } from './auth0-context';
|
|
3
4
|
/**
|
|
4
5
|
* Options for the withAuthenticationRequired Higher Order Component
|
|
5
6
|
*/
|
|
@@ -52,6 +53,12 @@ export interface WithAuthenticationRequiredOptions {
|
|
|
52
53
|
* whether or not they are authorized to view the component.
|
|
53
54
|
*/
|
|
54
55
|
claimCheck?: (claims?: User) => boolean;
|
|
56
|
+
/**
|
|
57
|
+
* The context to be used when calling useAuth0, this should only be provided if you are using multiple Auth0Providers
|
|
58
|
+
* within your application and you wish to tie a specific component to a Auth0Provider other than the Auth0Provider
|
|
59
|
+
* associated with the default Auth0Context.
|
|
60
|
+
*/
|
|
61
|
+
context?: React.Context<Auth0ContextInterface>;
|
|
55
62
|
}
|
|
56
63
|
/**
|
|
57
64
|
* ```js
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-authentication-required.d.ts","sourceRoot":"","sources":["../src/with-authentication-required.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAa,EAAE,EAAE,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"with-authentication-required.d.ts","sourceRoot":"","sources":["../src/with-authentication-required.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAa,EAAE,EAAE,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEjE,OAAqB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAatE;;GAEG;AACH,MAAM,WAAW,iCAAiC;IAChD;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;IACnC;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,CAAC,OAAO,CAAC;IAClC;;;;;;;;;;;;;OAaG;IACH,YAAY,CAAC,EAAE,oBAAoB,CAAC;IACpC;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,IAAI,KAAK,OAAO,CAAC;IAExC;;;;OAIG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;CAChD;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,0BAA0B,kEAErB,iCAAiC,gBA4C3C,CAAC;AAEF,eAAe,0BAA0B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Auth0",
|
|
3
3
|
"name": "@auth0/auth0-react",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.12.0",
|
|
5
5
|
"description": "Auth0 SDK for React Single Page Applications (SPA)",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"auth0",
|
|
@@ -39,8 +39,7 @@
|
|
|
39
39
|
"test:nextjs:watch": "start-server-and-test start:api 3001 start:nextjs 3000 cypress:open",
|
|
40
40
|
"test:integration": "npm run test:cra && npm run test:gatsby && npm run test:nextjs",
|
|
41
41
|
"cypress:run": "cypress run --spec 'cypress/integration/smoke.test.ts'",
|
|
42
|
-
"cypress:open": "cypress open"
|
|
43
|
-
"codecov": "codecov"
|
|
42
|
+
"cypress:open": "cypress open"
|
|
44
43
|
},
|
|
45
44
|
"repository": {
|
|
46
45
|
"type": "git",
|
|
@@ -63,7 +62,6 @@
|
|
|
63
62
|
"@typescript-eslint/eslint-plugin": "^5.17.0",
|
|
64
63
|
"@typescript-eslint/parser": "^5.17.0",
|
|
65
64
|
"browserstack-cypress-cli": "^1.1.2",
|
|
66
|
-
"codecov": "^3.8.2",
|
|
67
65
|
"cypress": "^9.5.3",
|
|
68
66
|
"eslint": "^8.12.0",
|
|
69
67
|
"eslint-plugin-react": "^7.29.4",
|
|
@@ -74,8 +72,8 @@
|
|
|
74
72
|
"oidc-provider": "^7.10.6",
|
|
75
73
|
"prettier": "2.6.2",
|
|
76
74
|
"pretty-quick": "^3.1.3",
|
|
77
|
-
"react": "^18.
|
|
78
|
-
"react-dom": "^18.
|
|
75
|
+
"react": "^18.2.0",
|
|
76
|
+
"react-dom": "^18.2.0",
|
|
79
77
|
"react-test-renderer": "^18.0.0",
|
|
80
78
|
"rollup": "^2.70.1",
|
|
81
79
|
"rollup-plugin-analyzer": "^4.0.0",
|
|
@@ -102,6 +100,6 @@
|
|
|
102
100
|
}
|
|
103
101
|
},
|
|
104
102
|
"dependencies": {
|
|
105
|
-
"@auth0/auth0-spa-js": "^1.22.
|
|
103
|
+
"@auth0/auth0-spa-js": "^1.22.4"
|
|
106
104
|
}
|
|
107
105
|
}
|
package/src/auth0-context.tsx
CHANGED
|
@@ -66,9 +66,9 @@ export interface Auth0ContextInterface<TUser extends User = User>
|
|
|
66
66
|
* the `auth0` cookie.
|
|
67
67
|
*/
|
|
68
68
|
getAccessTokenSilently: {
|
|
69
|
-
(
|
|
70
|
-
|
|
71
|
-
>;
|
|
69
|
+
(
|
|
70
|
+
options: GetTokenSilentlyOptions & { detailedResponse: true }
|
|
71
|
+
): Promise<GetTokenSilentlyVerboseResponse>;
|
|
72
72
|
(options?: GetTokenSilentlyOptions): Promise<string>;
|
|
73
73
|
(options: GetTokenSilentlyOptions): Promise<
|
|
74
74
|
GetTokenSilentlyVerboseResponse | string
|
|
@@ -190,7 +190,7 @@ const stub = (): never => {
|
|
|
190
190
|
/**
|
|
191
191
|
* @ignore
|
|
192
192
|
*/
|
|
193
|
-
const initialContext = {
|
|
193
|
+
export const initialContext = {
|
|
194
194
|
...initialAuthState,
|
|
195
195
|
buildAuthorizeUrl: stub,
|
|
196
196
|
buildLogoutUrl: stub,
|
package/src/auth0-provider.tsx
CHANGED
|
@@ -19,8 +19,12 @@ import {
|
|
|
19
19
|
RedirectLoginResult,
|
|
20
20
|
ICache,
|
|
21
21
|
GetTokenSilentlyOptions,
|
|
22
|
+
User,
|
|
22
23
|
} from '@auth0/auth0-spa-js';
|
|
23
|
-
import Auth0Context, {
|
|
24
|
+
import Auth0Context, {
|
|
25
|
+
Auth0ContextInterface,
|
|
26
|
+
RedirectLoginOptions,
|
|
27
|
+
} from './auth0-context';
|
|
24
28
|
import { hasAuthParams, loginError, tokenError } from './utils';
|
|
25
29
|
import { reducer } from './reducer';
|
|
26
30
|
import { initialAuthState } from './auth-state';
|
|
@@ -46,7 +50,7 @@ export interface Auth0ProviderOptions {
|
|
|
46
50
|
* It uses `window.history` but you might want to overwrite this if you are using a custom router, like `react-router-dom`
|
|
47
51
|
* See the EXAMPLES.md for more info.
|
|
48
52
|
*/
|
|
49
|
-
onRedirectCallback?: (appState?: AppState) => void;
|
|
53
|
+
onRedirectCallback?: (appState?: AppState, user?: User) => void;
|
|
50
54
|
/**
|
|
51
55
|
* By default, if the page url has code/state params, the SDK will treat them as Auth0's and attempt to exchange the
|
|
52
56
|
* code for a token. In some cases the code might be for something else (another OAuth SDK perhaps). In these
|
|
@@ -159,6 +163,24 @@ export interface Auth0ProviderOptions {
|
|
|
159
163
|
* the Login Widget.
|
|
160
164
|
*/
|
|
161
165
|
connection?: string;
|
|
166
|
+
/**
|
|
167
|
+
* Context to be used when creating the Auth0Provider, defaults to the internally created context.
|
|
168
|
+
*
|
|
169
|
+
* This allows multiple Auth0Providers to be nested within the same application, the context value can then be
|
|
170
|
+
* passed to useAuth0, withAuth0, or withAuthenticationRequired to use that specific Auth0Provider to access
|
|
171
|
+
* auth state and methods specifically tied to the provider that the context belongs to.
|
|
172
|
+
*
|
|
173
|
+
* When using multiple Auth0Providers in a single application you should do the following to ensure sessions are not
|
|
174
|
+
* overwritten:
|
|
175
|
+
*
|
|
176
|
+
* * Configure a different redirect_uri for each Auth0Provider, and set skipRedirectCallback for each provider to ignore
|
|
177
|
+
* the others redirect_uri
|
|
178
|
+
* * If using localstorage for both Auth0Providers, ensure that the audience and scope are different for so that the key
|
|
179
|
+
* used to store data is different
|
|
180
|
+
*
|
|
181
|
+
* For a sample on using multiple Auth0Providers review the [React Account Linking Sample](https://github.com/auth0-samples/auth0-link-accounts-sample/tree/react-variant)
|
|
182
|
+
*/
|
|
183
|
+
context?: React.Context<Auth0ContextInterface>;
|
|
162
184
|
/**
|
|
163
185
|
* If you need to send custom parameters to the Authorization Server,
|
|
164
186
|
* make sure to use the original parameter name.
|
|
@@ -235,6 +257,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
|
|
|
235
257
|
children,
|
|
236
258
|
skipRedirectCallback,
|
|
237
259
|
onRedirectCallback = defaultOnRedirectCallback,
|
|
260
|
+
context = Auth0Context,
|
|
238
261
|
...clientOpts
|
|
239
262
|
} = opts;
|
|
240
263
|
const [client] = useState(
|
|
@@ -250,13 +273,15 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
|
|
|
250
273
|
didInitialise.current = true;
|
|
251
274
|
(async (): Promise<void> => {
|
|
252
275
|
try {
|
|
276
|
+
let user: User | undefined;
|
|
253
277
|
if (hasAuthParams() && !skipRedirectCallback) {
|
|
254
278
|
const { appState } = await client.handleRedirectCallback();
|
|
255
|
-
|
|
279
|
+
user = await client.getUser();
|
|
280
|
+
onRedirectCallback(appState, user);
|
|
256
281
|
} else {
|
|
257
282
|
await client.checkSession();
|
|
283
|
+
user = await client.getUser();
|
|
258
284
|
}
|
|
259
|
-
const user = await client.getUser();
|
|
260
285
|
dispatch({ type: 'INITIALISED', user });
|
|
261
286
|
} catch (error) {
|
|
262
287
|
dispatch({ type: 'ERROR', error: loginError(error) });
|
|
@@ -400,11 +425,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
|
|
|
400
425
|
handleRedirectCallback,
|
|
401
426
|
]);
|
|
402
427
|
|
|
403
|
-
return
|
|
404
|
-
<Auth0Context.Provider value={contextValue}>
|
|
405
|
-
{children}
|
|
406
|
-
</Auth0Context.Provider>
|
|
407
|
-
);
|
|
428
|
+
return <context.Provider value={contextValue}>{children}</context.Provider>;
|
|
408
429
|
};
|
|
409
430
|
|
|
410
431
|
export default Auth0Provider;
|
package/src/index.tsx
CHANGED
package/src/use-auth0.tsx
CHANGED
|
@@ -24,7 +24,9 @@ import Auth0Context, { Auth0ContextInterface } from './auth0-context';
|
|
|
24
24
|
*
|
|
25
25
|
* TUser is an optional type param to provide a type to the `user` field.
|
|
26
26
|
*/
|
|
27
|
-
const useAuth0 = <TUser extends User = User>(
|
|
28
|
-
|
|
27
|
+
const useAuth0 = <TUser extends User = User>(
|
|
28
|
+
context = Auth0Context
|
|
29
|
+
): Auth0ContextInterface<TUser> =>
|
|
30
|
+
useContext(context) as Auth0ContextInterface<TUser>;
|
|
29
31
|
|
|
30
|
-
export default useAuth0;
|
|
32
|
+
export default useAuth0;
|
package/src/with-auth0.tsx
CHANGED
|
@@ -21,18 +21,22 @@ export interface WithAuth0Props {
|
|
|
21
21
|
* export default withAuth0(MyComponent);
|
|
22
22
|
* ```
|
|
23
23
|
*
|
|
24
|
-
* Wrap your class components in this Higher Order Component to give them access to the Auth0Context
|
|
24
|
+
* Wrap your class components in this Higher Order Component to give them access to the Auth0Context.
|
|
25
|
+
*
|
|
26
|
+
* Providing a context as the second argument allows you to configure the Auth0Provider the Auth0Context
|
|
27
|
+
* should come from f you have multiple within your application.
|
|
25
28
|
*/
|
|
26
29
|
const withAuth0 = <P extends WithAuth0Props>(
|
|
27
|
-
Component: ComponentType<P
|
|
30
|
+
Component: ComponentType<P>,
|
|
31
|
+
context = Auth0Context
|
|
28
32
|
): ComponentType<Omit<P, keyof WithAuth0Props>> => {
|
|
29
33
|
return function WithAuth(props): JSX.Element {
|
|
30
34
|
return (
|
|
31
|
-
<
|
|
35
|
+
<context.Consumer>
|
|
32
36
|
{(auth: Auth0ContextInterface): JSX.Element => (
|
|
33
37
|
<Component {...(props as P)} auth0={auth} />
|
|
34
38
|
)}
|
|
35
|
-
</
|
|
39
|
+
</context.Consumer>
|
|
36
40
|
);
|
|
37
41
|
};
|
|
38
42
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { ComponentType, useEffect, FC } from 'react';
|
|
2
2
|
import { RedirectLoginOptions, User } from '@auth0/auth0-spa-js';
|
|
3
3
|
import useAuth0 from './use-auth0';
|
|
4
|
+
import Auth0Context, { Auth0ContextInterface } from './auth0-context';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @ignore
|
|
@@ -65,6 +66,13 @@ export interface WithAuthenticationRequiredOptions {
|
|
|
65
66
|
* whether or not they are authorized to view the component.
|
|
66
67
|
*/
|
|
67
68
|
claimCheck?: (claims?: User) => boolean;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The context to be used when calling useAuth0, this should only be provided if you are using multiple Auth0Providers
|
|
72
|
+
* within your application and you wish to tie a specific component to a Auth0Provider other than the Auth0Provider
|
|
73
|
+
* associated with the default Auth0Context.
|
|
74
|
+
*/
|
|
75
|
+
context?: React.Context<Auth0ContextInterface>;
|
|
68
76
|
}
|
|
69
77
|
|
|
70
78
|
/**
|
|
@@ -80,14 +88,17 @@ const withAuthenticationRequired = <P extends object>(
|
|
|
80
88
|
options: WithAuthenticationRequiredOptions = {}
|
|
81
89
|
): FC<P> => {
|
|
82
90
|
return function WithAuthenticationRequired(props: P): JSX.Element {
|
|
83
|
-
const { user, isAuthenticated, isLoading, loginWithRedirect } = useAuth0();
|
|
84
91
|
const {
|
|
85
92
|
returnTo = defaultReturnTo,
|
|
86
93
|
onRedirecting = defaultOnRedirecting,
|
|
87
94
|
claimCheck = (): boolean => true,
|
|
88
95
|
loginOptions,
|
|
96
|
+
context = Auth0Context,
|
|
89
97
|
} = options;
|
|
90
98
|
|
|
99
|
+
const { user, isAuthenticated, isLoading, loginWithRedirect } =
|
|
100
|
+
useAuth0(context);
|
|
101
|
+
|
|
91
102
|
/**
|
|
92
103
|
* The route is authenticated if the user has valid auth and there are no
|
|
93
104
|
* JWT claim mismatches.
|