@auth0/auth0-react 1.8.0 → 1.9.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/reducer.d.ts CHANGED
@@ -14,6 +14,6 @@ declare type Action = {
14
14
  /**
15
15
  * Handles how that state changes in the `useAuth0` hook.
16
16
  */
17
- export declare const reducer: (state: AuthState<User>, action: Action) => AuthState<User>;
17
+ export declare const reducer: (state: AuthState, action: Action) => AuthState;
18
18
  export {};
19
19
  //# sourceMappingURL=reducer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../src/reducer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,aAAK,MAAM,GACP;IAAE,IAAI,EAAE,qBAAqB,CAAA;CAAE,GAC/B;IACE,IAAI,EACA,aAAa,GACb,sBAAsB,GACtB,2BAA2B,GAC3B,0BAA0B,CAAC;IAC/B,IAAI,CAAC,EAAE,IAAI,CAAC;CACb,GACD;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,OAAO,6DAuCnB,CAAC"}
1
+ {"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../src/reducer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,aAAK,MAAM,GACP;IAAE,IAAI,EAAE,qBAAqB,CAAA;CAAE,GAC/B;IACE,IAAI,EACA,aAAa,GACb,sBAAsB,GACtB,2BAA2B,GAC3B,0BAA0B,CAAC;IAC/B,IAAI,CAAC,EAAE,IAAI,CAAC;CACb,GACD;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,OAAO,UAAW,SAAS,UAAU,MAAM,KAAG,SAuC1D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.tsx"],"names":[],"mappings":"AAMA,eAAO,MAAM,aAAa,oCAEG,CAAC;AAc9B,eAAO,MAAM,UAAU;;;wCAAmC,CAAC;AAE3D,eAAO,MAAM,UAAU;;;wCAA8C,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.tsx"],"names":[],"mappings":"AAMA,eAAO,MAAM,aAAa,6BAA4C,OAEzC,CAAC;AAc9B,eAAO,MAAM,UAAU;WAXG,MAAM;;mCAC7B,KAUuD,CAAC;AAE3D,eAAO,MAAM,UAAU;WAbG,MAAM;;mCAC7B,KAYkE,CAAC"}
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { ComponentType } from 'react';
2
2
  import { Auth0ContextInterface } from './auth0-context';
3
3
  /**
4
4
  * Components wrapped in `withAuth0` will have an additional `auth0` prop
@@ -21,6 +21,6 @@ export interface WithAuth0Props {
21
21
  *
22
22
  * Wrap your class components in this Higher Order Component to give them access to the Auth0Context
23
23
  */
24
- declare const withAuth0: <P extends WithAuth0Props>(Component: React.ComponentType<P>) => React.ComponentType<Pick<P, Exclude<keyof P, "auth0">>>;
24
+ declare const withAuth0: <P extends WithAuth0Props>(Component: React.ComponentType<P>) => React.ComponentType<Omit<P, "auth0">>;
25
25
  export default withAuth0;
26
26
  //# sourceMappingURL=with-auth0.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"with-auth0.d.ts","sourceRoot":"","sources":["../src/with-auth0.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAC7C,OAAqB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,qBAAqB,CAAC;CAC9B;AAED;;;;;;;;;;;;;;GAcG;AACH,QAAA,MAAM,SAAS,0HAQd,CAAC;AAEF,eAAe,SAAS,CAAC"}
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;;;;;;;;;;;;;;GAcG;AACH,QAAA,MAAM,SAAS,wGAQd,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { ComponentType, FC } from 'react';
2
2
  import { RedirectLoginOptions, User } from '@auth0/auth0-spa-js';
3
3
  /**
4
4
  * Options for the withAuthenticationRequired Higher Order Component
@@ -1 +1 @@
1
- {"version":3,"file":"with-authentication-required.d.ts","sourceRoot":"","sources":["../src/with-authentication-required.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAcjE;;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;CACzC;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,0BAA0B,mHA2C/B,CAAC;AAEF,eAAe,0BAA0B,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;AAcjE;;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;CACzC;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,0BAA0B,kEAErB,iCAAiC,gBAyC3C,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.8.0",
4
+ "version": "1.9.0",
5
5
  "description": "Auth0 SDK for React Single Page Applications (SPA)",
6
6
  "keywords": [
7
7
  "auth0",
@@ -57,7 +57,7 @@
57
57
  "@testing-library/jest-dom": "^5.5.0",
58
58
  "@testing-library/react": "^10.0.4",
59
59
  "@testing-library/react-hooks": "^3.2.1",
60
- "@types/jest": "^25.2.1",
60
+ "@types/jest": "^27.4.0",
61
61
  "@types/react": "^16.9.34",
62
62
  "@types/react-dom": "^16.9.6",
63
63
  "@typescript-eslint/eslint-plugin": "^2.30.0",
@@ -69,7 +69,7 @@
69
69
  "eslint-plugin-react": "^7.19.0",
70
70
  "eslint-plugin-react-hooks": "^4.0.0",
71
71
  "husky": "^4.2.5",
72
- "jest": "^26.6.3",
72
+ "jest": "^27.4.7",
73
73
  "jest-junit": "^10.0.0",
74
74
  "oidc-provider": "^7.6.0",
75
75
  "prettier": "2.0.5",
@@ -87,10 +87,10 @@
87
87
  "rollup-plugin-terser": "^7.0.0",
88
88
  "rollup-plugin-typescript2": "^0.27.0",
89
89
  "start-server-and-test": "^1.11.0",
90
- "ts-jest": "^26.5.0",
90
+ "ts-jest": "^27.1.2",
91
91
  "tslib": "^1.11.1",
92
92
  "typedoc": "^0.20.32",
93
- "typescript": "^3.8.3"
93
+ "typescript": "^4.5.4"
94
94
  },
95
95
  "peerDependencies": {
96
96
  "react": "^16.11.0 || ^17",
@@ -102,6 +102,6 @@
102
102
  }
103
103
  },
104
104
  "dependencies": {
105
- "@auth0/auth0-spa-js": "^1.18.0"
105
+ "@auth0/auth0-spa-js": "^1.19.3"
106
106
  }
107
107
  }
@@ -11,6 +11,7 @@ import {
11
11
  RedirectLoginOptions as Auth0RedirectLoginOptions,
12
12
  RedirectLoginResult,
13
13
  User,
14
+ GetTokenSilentlyVerboseResponse,
14
15
  } from '@auth0/auth0-spa-js';
15
16
  import { createContext } from 'react';
16
17
  import { AuthState, initialAuthState } from './auth-state';
@@ -64,9 +65,15 @@ export interface Auth0ContextInterface<TUser extends User = User>
64
65
  * Note that in all cases, falling back to an iframe requires access to
65
66
  * the `auth0` cookie.
66
67
  */
67
- getAccessTokenSilently: (
68
- options?: GetTokenSilentlyOptions
69
- ) => Promise<string>;
68
+ getAccessTokenSilently: {
69
+ (options: GetTokenSilentlyOptions & { detailedResponse: true }): Promise<
70
+ GetTokenSilentlyVerboseResponse
71
+ >;
72
+ (options?: GetTokenSilentlyOptions): Promise<string>;
73
+ (options: GetTokenSilentlyOptions): Promise<
74
+ GetTokenSilentlyVerboseResponse | string
75
+ >;
76
+ };
70
77
 
71
78
  /**
72
79
  * ```js
@@ -92,7 +99,9 @@ export interface Auth0ContextInterface<TUser extends User = User>
92
99
  *
93
100
  * Returns all claims from the id_token if available.
94
101
  */
95
- getIdTokenClaims: (options?: GetIdTokenClaimsOptions) => Promise<IdToken>;
102
+ getIdTokenClaims: (
103
+ options?: GetIdTokenClaimsOptions
104
+ ) => Promise<IdToken | undefined>;
96
105
 
97
106
  /**
98
107
  * ```js
@@ -1,19 +1,23 @@
1
- import React, { useCallback, useEffect, useReducer, useState } from 'react';
1
+ import React, {
2
+ useCallback,
3
+ useEffect,
4
+ useMemo,
5
+ useReducer,
6
+ useState,
7
+ } from 'react';
2
8
  import {
3
9
  Auth0Client,
4
10
  Auth0ClientOptions,
5
11
  CacheLocation,
6
- IdToken,
7
12
  LogoutOptions,
8
13
  LogoutUrlOptions,
9
14
  PopupLoginOptions,
10
15
  PopupConfigOptions,
11
16
  RedirectLoginOptions as Auth0RedirectLoginOptions,
12
17
  GetTokenWithPopupOptions,
13
- GetTokenSilentlyOptions,
14
- GetIdTokenClaimsOptions,
15
18
  RedirectLoginResult,
16
19
  ICache,
20
+ GetTokenSilentlyOptions,
17
21
  } from '@auth0/auth0-spa-js';
18
22
  import Auth0Context, { RedirectLoginOptions } from './auth0-context';
19
23
  import { hasAuthParams, loginError, tokenError } from './utils';
@@ -148,6 +152,12 @@ export interface Auth0ProviderOptions {
148
152
  * The Id of an invitation to accept. This is available from the user invitation URL that is given when participating in a user invitation flow.
149
153
  */
150
154
  invitation?: string;
155
+ /**
156
+ * The name of the connection configured for your application.
157
+ * If null, it will redirect to the Auth0 Login Page and show
158
+ * the Login Widget.
159
+ */
160
+ connection?: string;
151
161
  /**
152
162
  * If you need to send custom parameters to the Authorization Server,
153
163
  * make sure to use the original parameter name.
@@ -298,7 +308,8 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
298
308
  );
299
309
 
300
310
  const getAccessTokenSilently = useCallback(
301
- async (opts?: GetTokenSilentlyOptions): Promise<string> => {
311
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
312
+ async (opts?: GetTokenSilentlyOptions): Promise<any> => {
302
313
  let token;
303
314
  try {
304
315
  token = await client.getTokenSilently(opts);
@@ -337,8 +348,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
337
348
  );
338
349
 
339
350
  const getIdTokenClaims = useCallback(
340
- (opts?: GetIdTokenClaimsOptions): Promise<IdToken> =>
341
- client.getIdTokenClaims(opts),
351
+ (opts) => client.getIdTokenClaims(opts),
342
352
  [client]
343
353
  );
344
354
 
@@ -358,21 +368,34 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
358
368
  [client]
359
369
  );
360
370
 
371
+ const contextValue = useMemo(() => {
372
+ return {
373
+ ...state,
374
+ buildAuthorizeUrl,
375
+ buildLogoutUrl,
376
+ getAccessTokenSilently,
377
+ getAccessTokenWithPopup,
378
+ getIdTokenClaims,
379
+ loginWithRedirect,
380
+ loginWithPopup,
381
+ logout,
382
+ handleRedirectCallback,
383
+ };
384
+ }, [
385
+ state,
386
+ buildAuthorizeUrl,
387
+ buildLogoutUrl,
388
+ getAccessTokenSilently,
389
+ getAccessTokenWithPopup,
390
+ getIdTokenClaims,
391
+ loginWithRedirect,
392
+ loginWithPopup,
393
+ logout,
394
+ handleRedirectCallback,
395
+ ]);
396
+
361
397
  return (
362
- <Auth0Context.Provider
363
- value={{
364
- ...state,
365
- buildAuthorizeUrl,
366
- buildLogoutUrl,
367
- getAccessTokenSilently,
368
- getAccessTokenWithPopup,
369
- getIdTokenClaims,
370
- loginWithRedirect,
371
- loginWithPopup,
372
- logout,
373
- handleRedirectCallback,
374
- }}
375
- >
398
+ <Auth0Context.Provider value={contextValue}>
376
399
  {children}
377
400
  </Auth0Context.Provider>
378
401
  );
@@ -28,7 +28,7 @@ const withAuth0 = <P extends WithAuth0Props>(
28
28
  ): ComponentType<Omit<P, keyof WithAuth0Props>> => (props): JSX.Element => (
29
29
  <Auth0Context.Consumer>
30
30
  {(auth: Auth0ContextInterface): JSX.Element => (
31
- <Component auth0={auth} {...(props as P)} />
31
+ <Component {...(props as P)} auth0={auth} />
32
32
  )}
33
33
  </Auth0Context.Consumer>
34
34
  );
@@ -84,8 +84,8 @@ const withAuthenticationRequired = <P extends object>(
84
84
  const {
85
85
  returnTo = defaultReturnTo,
86
86
  onRedirecting = defaultOnRedirecting,
87
- loginOptions = {},
88
87
  claimCheck = (): boolean => true,
88
+ loginOptions,
89
89
  } = options;
90
90
 
91
91
  /**
@@ -101,7 +101,7 @@ const withAuthenticationRequired = <P extends object>(
101
101
  const opts = {
102
102
  ...loginOptions,
103
103
  appState: {
104
- ...loginOptions.appState,
104
+ ...(loginOptions && loginOptions.appState),
105
105
  returnTo: typeof returnTo === 'function' ? returnTo() : returnTo,
106
106
  },
107
107
  };