@auth0/auth0-react 1.12.1 → 2.0.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/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, initialContext, RedirectLoginOptions, } from './auth0-context';
6
- export { PopupLoginOptions, PopupConfigOptions, GetIdTokenClaimsOptions, GetTokenWithPopupOptions, LogoutOptions, LogoutUrlOptions, CacheLocation, GetTokenSilentlyOptions, IdToken, User, ICache, InMemoryCache, LocalStorageCache, Cacheable, } from '@auth0/auth0-spa-js';
5
+ export { default as Auth0Context, Auth0ContextInterface, initialContext, LogoutOptions, RedirectLoginOptions, } from './auth0-context';
6
+ export { AuthorizationParams, PopupLoginOptions, PopupConfigOptions, GetTokenWithPopupOptions, 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
@@ -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,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"}
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,aAAa,EACb,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,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/reducer.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { User } from '@auth0/auth0-spa-js';
2
2
  import { AuthState } from './auth-state';
3
- declare type Action = {
3
+ type Action = {
4
4
  type: 'LOGIN_POPUP_STARTED';
5
5
  } | {
6
6
  type: 'INITIALISED' | 'LOGIN_POPUP_COMPLETE' | 'GET_ACCESS_TOKEN_COMPLETE' | 'HANDLE_REDIRECT_COMPLETE';
@@ -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,UAAW,SAAS,UAAU,MAAM,KAAG,SAuC1D,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,KAAK,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,6 +1,5 @@
1
1
  import React, { ComponentType, FC } from 'react';
2
- import { RedirectLoginOptions, User } from '@auth0/auth0-spa-js';
3
- import { Auth0ContextInterface } from './auth0-context';
2
+ import { Auth0ContextInterface, RedirectLoginOptions } from './auth0-context';
4
3
  /**
5
4
  * Options for the withAuthenticationRequired Higher Order Component
6
5
  */
@@ -48,11 +47,6 @@ export interface WithAuthenticationRequiredOptions {
48
47
  * This will be merged with the `returnTo` option used by the `onRedirectCallback` handler.
49
48
  */
50
49
  loginOptions?: RedirectLoginOptions;
51
- /**
52
- * Check the user object for JWT claims and return a boolean indicating
53
- * whether or not they are authorized to view the component.
54
- */
55
- claimCheck?: (claims?: User) => boolean;
56
50
  /**
57
51
  * The context to be used when calling useAuth0, this should only be provided if you are using multiple Auth0Providers
58
52
  * within your application and you wish to tie a specific component to a Auth0Provider other than the Auth0Provider
@@ -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;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"}
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;AAE5D,OAAqB,EACnB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAazB;;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;;;;OAIG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;CAChD;AAED;;;;;;;GAOG;AACH,QAAA,MAAM,0BAA0B,kEAErB,iCAAiC,gBAqC3C,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.12.1",
4
+ "version": "2.0.0",
5
5
  "description": "Auth0 SDK for React Single Page Applications (SPA)",
6
6
  "keywords": [
7
7
  "auth0",
@@ -31,7 +31,7 @@
31
31
  "start:gatsby": "npm start --prefix=examples/gatsby-app",
32
32
  "start:nextjs": "npm run dev --prefix=examples/nextjs-app",
33
33
  "start:api": "npm start --prefix=examples/users-api",
34
- "test:cra": "start-server-and-test start:api 3001 start:cra 3000 cypress:run",
34
+ "test:cra": "start-server-and-test start:api 3001 start:cra http-get://127.0.0.1:3000 cypress:run",
35
35
  "test:cra:watch": "start-server-and-test start:api 3001 start:cra 3000 cypress:open",
36
36
  "test:gatsby": "start-server-and-test start:api 3001 start:gatsby 3000 cypress:run",
37
37
  "test:gatsby:watch": "start-server-and-test start:api 3001 start:gatsby 3000 cypress:open",
@@ -51,8 +51,9 @@
51
51
  },
52
52
  "homepage": "https://github.com/auth0/auth0-react#readme",
53
53
  "devDependencies": {
54
- "@rollup/plugin-node-resolve": "^13.1.3",
55
- "@rollup/plugin-replace": "^4.0.0",
54
+ "@rollup/plugin-node-resolve": "^15.0.1",
55
+ "@rollup/plugin-replace": "^5.0.1",
56
+ "@rollup/plugin-terser": "^0.1.0",
56
57
  "@testing-library/jest-dom": "^5.16.5",
57
58
  "@testing-library/react": "^13.4.0",
58
59
  "@testing-library/react-hooks": "^7.0.2",
@@ -61,7 +62,7 @@
61
62
  "@types/react-dom": "^17.0.18",
62
63
  "@typescript-eslint/eslint-plugin": "^5.45.0",
63
64
  "@typescript-eslint/parser": "^5.45.0",
64
- "browserstack-cypress-cli": "1.8.1",
65
+ "browserstack-cypress-cli": "^1.19.1",
65
66
  "cypress": "^9.7.0",
66
67
  "eslint": "^8.28.0",
67
68
  "eslint-plugin-react": "^7.31.11",
@@ -70,26 +71,25 @@
70
71
  "jest": "^29.3.1",
71
72
  "jest-environment-jsdom": "^29.3.1",
72
73
  "jest-junit": "^15.0.0",
73
- "oidc-provider": "^7.10.6",
74
- "prettier": "2.8.0",
74
+ "oidc-provider": "^8.0.0",
75
+ "prettier": "^2.8.1",
75
76
  "pretty-quick": "^3.1.3",
76
77
  "react": "^18.2.0",
77
78
  "react-dom": "^18.2.0",
78
79
  "react-test-renderer": "^18.2.0",
79
- "rollup": "^2.70.1",
80
+ "rollup": "^3.7.0",
80
81
  "rollup-plugin-analyzer": "^4.0.0",
81
82
  "rollup-plugin-delete": "^2.0.0",
82
83
  "rollup-plugin-dev": "^1.1.3",
83
84
  "rollup-plugin-livereload": "^2.0.5",
84
85
  "rollup-plugin-peer-deps-external": "^2.2.4",
85
- "rollup-plugin-serve": "^1.1.0",
86
- "rollup-plugin-terser": "^7.0.2",
87
- "rollup-plugin-typescript2": "^0.31.2",
88
- "start-server-and-test": "^1.14.0",
86
+ "rollup-plugin-serve": "^2.0.2",
87
+ "rollup-plugin-typescript2": "^0.34.1",
88
+ "start-server-and-test": "^1.15.2",
89
89
  "ts-jest": "^29.0.3",
90
- "tslib": "^2.3.1",
91
- "typedoc": "^0.22.13",
92
- "typescript": "^4.6.3"
90
+ "tslib": "^2.4.1",
91
+ "typedoc": "^0.23.21",
92
+ "typescript": "^4.9.4"
93
93
  },
94
94
  "peerDependencies": {
95
95
  "react": "^16.11.0 || ^17 || ^18",
@@ -101,6 +101,6 @@
101
101
  }
102
102
  },
103
103
  "dependencies": {
104
- "@auth0/auth0-spa-js": "^1.22.6"
104
+ "@auth0/auth0-spa-js": "^2.0.2"
105
105
  }
106
106
  }
@@ -1,40 +1,24 @@
1
1
  import {
2
- BaseLoginOptions,
3
- GetIdTokenClaimsOptions,
4
2
  GetTokenSilentlyOptions,
5
3
  GetTokenWithPopupOptions,
6
4
  IdToken,
7
- LogoutOptions,
8
- LogoutUrlOptions,
5
+ LogoutOptions as SPALogoutOptions,
9
6
  PopupLoginOptions,
10
7
  PopupConfigOptions,
11
- RedirectLoginOptions as Auth0RedirectLoginOptions,
12
8
  RedirectLoginResult,
13
9
  User,
14
10
  GetTokenSilentlyVerboseResponse,
11
+ RedirectLoginOptions as SPARedirectLoginOptions,
15
12
  } from '@auth0/auth0-spa-js';
16
13
  import { createContext } from 'react';
17
14
  import { AuthState, initialAuthState } from './auth-state';
15
+ import { AppState } from './auth0-provider';
18
16
 
19
- export interface RedirectLoginOptions extends BaseLoginOptions {
20
- /**
21
- * The URL where Auth0 will redirect your browser to with
22
- * the authentication result. It must be whitelisted in
23
- * the "Allowed Callback URLs" field in your Auth0 Application's
24
- * settings.
25
- */
26
- redirectUri?: string;
27
-
28
- /**
29
- * Used to store state before doing the redirect
30
- */
31
- appState?: any; // eslint-disable-line @typescript-eslint/no-explicit-any
32
-
33
- /**
34
- * Used to add to the URL fragment before redirecting
35
- */
36
- fragment?: string;
37
- }
17
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
18
+ export interface LogoutOptions extends Omit<SPALogoutOptions, 'onRedirect'> {}
19
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
20
+ export interface RedirectLoginOptions<TAppState = AppState>
21
+ extends Omit<SPARedirectLoginOptions<TAppState>, 'onRedirect'> {}
38
22
 
39
23
  /**
40
24
  * Contains the authenticated state and authentication methods provided by the `useAuth0` hook.
@@ -90,7 +74,7 @@ export interface Auth0ContextInterface<TUser extends User = User>
90
74
  getAccessTokenWithPopup: (
91
75
  options?: GetTokenWithPopupOptions,
92
76
  config?: PopupConfigOptions
93
- ) => Promise<string>;
77
+ ) => Promise<string | undefined>;
94
78
 
95
79
  /**
96
80
  * ```js
@@ -99,9 +83,7 @@ export interface Auth0ContextInterface<TUser extends User = User>
99
83
  *
100
84
  * Returns all claims from the id_token if available.
101
85
  */
102
- getIdTokenClaims: (
103
- options?: GetIdTokenClaimsOptions
104
- ) => Promise<IdToken | undefined>;
86
+ getIdTokenClaims: () => Promise<IdToken | undefined>;
105
87
 
106
88
  /**
107
89
  * ```js
@@ -112,7 +94,9 @@ export interface Auth0ContextInterface<TUser extends User = User>
112
94
  * provided as arguments. Random and secure `state` and `nonce`
113
95
  * parameters will be auto-generated.
114
96
  */
115
- loginWithRedirect: (options?: RedirectLoginOptions) => Promise<void>;
97
+ loginWithRedirect: (
98
+ options?: RedirectLoginOptions<AppState>
99
+ ) => Promise<void>;
116
100
 
117
101
  /**
118
102
  * ```js
@@ -140,35 +124,11 @@ export interface Auth0ContextInterface<TUser extends User = User>
140
124
  *
141
125
  * Clears the application session and performs a redirect to `/v2/logout`, using
142
126
  * the parameters provided as arguments, to clear the Auth0 session.
143
- * If the `federated` option is specified, it also clears the Identity Provider session.
144
- * If the `localOnly` option is specified, it only clears the application session.
145
- * It is invalid to set both the `federated` and `localOnly` options to `true`,
146
- * and an error will be thrown if you do.
127
+ * If the `logoutParams.federated` option is specified, it also clears the Identity Provider session.
147
128
  * [Read more about how Logout works at Auth0](https://auth0.com/docs/logout).
148
129
  */
149
130
  logout: (options?: LogoutOptions) => void;
150
131
 
151
- /**
152
- * ```js
153
- * const authUrl = await buildAuthorizeUrl();
154
- * ```
155
- *
156
- * Builds an `/authorize` URL for loginWithRedirect using the parameters
157
- * provided as arguments. Random and secure `state` and `nonce`
158
- * parameters will be auto-generated.
159
- */
160
- buildAuthorizeUrl: (options?: Auth0RedirectLoginOptions) => Promise<string>;
161
-
162
- /**
163
- * ```js
164
- * const logoutUrl = buildLogoutUrl();
165
- * ```
166
- *
167
- * returns a URL to the logout endpoint using the parameters provided as arguments.
168
- * @param options
169
- */
170
- buildLogoutUrl: (options?: LogoutUrlOptions) => string;
171
-
172
132
  /**
173
133
  * After the browser redirects back to the callback page,
174
134
  * call `handleRedirectCallback` to handle success and error
@@ -9,20 +9,16 @@ import React, {
9
9
  import {
10
10
  Auth0Client,
11
11
  Auth0ClientOptions,
12
- CacheLocation,
13
- LogoutOptions,
14
- LogoutUrlOptions,
15
12
  PopupLoginOptions,
16
13
  PopupConfigOptions,
17
- RedirectLoginOptions as Auth0RedirectLoginOptions,
18
14
  GetTokenWithPopupOptions,
19
15
  RedirectLoginResult,
20
- ICache,
21
16
  GetTokenSilentlyOptions,
22
17
  User,
23
18
  } from '@auth0/auth0-spa-js';
24
19
  import Auth0Context, {
25
20
  Auth0ContextInterface,
21
+ LogoutOptions,
26
22
  RedirectLoginOptions,
27
23
  } from './auth0-context';
28
24
  import { hasAuthParams, loginError, tokenError } from './utils';
@@ -40,7 +36,7 @@ export type AppState = {
40
36
  /**
41
37
  * The main configuration to instantiate the `Auth0Provider`.
42
38
  */
43
- export interface Auth0ProviderOptions {
39
+ export interface Auth0ProviderOptions extends Auth0ClientOptions {
44
40
  /**
45
41
  * The child nodes your Provider has wrapped
46
42
  */
@@ -65,104 +61,6 @@ export interface Auth0ProviderOptions {
65
61
  * ```
66
62
  */
67
63
  skipRedirectCallback?: boolean;
68
- /**
69
- * Your Auth0 account domain such as `'example.auth0.com'`,
70
- * `'example.eu.auth0.com'` or , `'example.mycompany.com'`
71
- * (when using [custom domains](https://auth0.com/docs/custom-domains))
72
- */
73
- domain: string;
74
- /**
75
- * The issuer to be used for validation of JWTs, optionally defaults to the domain above
76
- */
77
- issuer?: string;
78
- /**
79
- * The Client ID found on your Application settings page
80
- */
81
- clientId: string;
82
- /**
83
- * The default URL where Auth0 will redirect your browser to with
84
- * the authentication result. It must be whitelisted in
85
- * the "Allowed Callback URLs" field in your Auth0 Application's
86
- * settings. If not provided here, it should be provided in the other
87
- * methods that provide authentication.
88
- */
89
- redirectUri?: string;
90
- /**
91
- * The value in seconds used to account for clock skew in JWT expirations.
92
- * Typically, this value is no more than a minute or two at maximum.
93
- * Defaults to 60s.
94
- */
95
- leeway?: number;
96
- /**
97
- * The location to use when storing cache data. Valid values are `memory` or `localstorage`.
98
- * The default setting is `memory`.
99
- *
100
- * Read more about [changing storage options in the Auth0 docs](https://auth0.com/docs/libraries/auth0-single-page-app-sdk#change-storage-options)
101
- */
102
- cacheLocation?: CacheLocation;
103
- /**
104
- * Specify a custom cache implementation to use for token storage and retrieval. This setting takes precedence over `cacheLocation` if they are both specified.
105
- *
106
- * Read more about [creating a custom cache](https://github.com/auth0/auth0-spa-js#creating-a-custom-cache)
107
- */
108
- cache?: ICache;
109
- /**
110
- * If true, refresh tokens are used to fetch new access tokens from the Auth0 server. If false, the legacy technique of using a hidden iframe and the `authorization_code` grant with `prompt=none` is used.
111
- * The default setting is `false`.
112
- *
113
- * **Note**: Use of refresh tokens must be enabled by an administrator on your Auth0 client application.
114
- */
115
- useRefreshTokens?: boolean;
116
- /**
117
- * A maximum number of seconds to wait before declaring background calls to /authorize as failed for timeout
118
- * Defaults to 60s.
119
- */
120
- authorizeTimeoutInSeconds?: number;
121
- /**
122
- * Changes to recommended defaults, like defaultScope
123
- */
124
- advancedOptions?: {
125
- /**
126
- * The default scope to be included with all requests.
127
- * If not provided, 'openid profile email' is used. This can be set to `null` in order to effectively remove the default scopes.
128
- *
129
- * Note: The `openid` scope is **always applied** regardless of this setting.
130
- */
131
- defaultScope?: string;
132
- };
133
- /**
134
- * Maximum allowable elapsed time (in seconds) since authentication.
135
- * If the last time the user authenticated is greater than this value,
136
- * the user must be reauthenticated.
137
- */
138
- maxAge?: string | number;
139
- /**
140
- * The default scope to be used on authentication requests.
141
- * The defaultScope defined in the Auth0Client is included
142
- * along with this scope
143
- */
144
- scope?: string;
145
- /**
146
- * The default audience to be used for requesting API access.
147
- */
148
- audience?: string;
149
- /**
150
- * The Id of an organization to log in to.
151
- *
152
- * This will specify an `organization` parameter in your user's login request and will add a step to validate
153
- * the `org_id` claim in your user's ID Token.
154
- */
155
- organization?: string;
156
- /**
157
- * 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.
158
- */
159
- invitation?: string;
160
- /**
161
- * The name of the connection configured for your application.
162
- * If null, it will redirect to the Auth0 Login Page and show
163
- * the Login Widget.
164
- */
165
- connection?: string;
166
64
  /**
167
65
  * Context to be used when creating the Auth0Provider, defaults to the internally created context.
168
66
  *
@@ -181,11 +79,6 @@ export interface Auth0ProviderOptions {
181
79
  * 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
80
  */
183
81
  context?: React.Context<Auth0ContextInterface>;
184
- /**
185
- * If you need to send custom parameters to the Authorization Server,
186
- * make sure to use the original parameter name.
187
- */
188
- [key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any
189
82
  }
190
83
 
191
84
  /**
@@ -200,12 +93,8 @@ declare const __VERSION__: string;
200
93
  const toAuth0ClientOptions = (
201
94
  opts: Auth0ProviderOptions
202
95
  ): Auth0ClientOptions => {
203
- const { clientId, redirectUri, maxAge, ...validOpts } = opts;
204
96
  return {
205
- ...validOpts,
206
- client_id: clientId,
207
- redirect_uri: redirectUri,
208
- max_age: maxAge,
97
+ ...opts,
209
98
  auth0Client: {
210
99
  name: 'auth0-react',
211
100
  version: __VERSION__,
@@ -213,22 +102,6 @@ const toAuth0ClientOptions = (
213
102
  };
214
103
  };
215
104
 
216
- /**
217
- * @ignore
218
- */
219
- const toAuth0LoginRedirectOptions = (
220
- opts?: RedirectLoginOptions
221
- ): Auth0RedirectLoginOptions | undefined => {
222
- if (!opts) {
223
- return;
224
- }
225
- const { redirectUri, ...validOpts } = opts;
226
- return {
227
- ...validOpts,
228
- redirect_uri: redirectUri,
229
- };
230
- };
231
-
232
105
  /**
233
106
  * @ignore
234
107
  */
@@ -289,20 +162,9 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
289
162
  })();
290
163
  }, [client, onRedirectCallback, skipRedirectCallback]);
291
164
 
292
- const buildAuthorizeUrl = useCallback(
293
- (opts?: RedirectLoginOptions): Promise<string> =>
294
- client.buildAuthorizeUrl(toAuth0LoginRedirectOptions(opts)),
295
- [client]
296
- );
297
-
298
- const buildLogoutUrl = useCallback(
299
- (opts?: LogoutUrlOptions): string => client.buildLogoutUrl(opts),
300
- [client]
301
- );
302
-
303
165
  const loginWithRedirect = useCallback(
304
166
  (opts?: RedirectLoginOptions): Promise<void> =>
305
- client.loginWithRedirect(toAuth0LoginRedirectOptions(opts)),
167
+ client.loginWithRedirect(opts),
306
168
  [client]
307
169
  );
308
170
 
@@ -325,15 +187,11 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
325
187
  );
326
188
 
327
189
  const logout = useCallback(
328
- (opts: LogoutOptions = {}): Promise<void> | void => {
329
- const maybePromise = client.logout(opts);
330
- if (opts.localOnly) {
331
- if (maybePromise && typeof maybePromise.then === 'function') {
332
- return maybePromise.then(() => dispatch({ type: 'LOGOUT' }));
333
- }
190
+ async (opts: LogoutOptions = {}): Promise<void> => {
191
+ await client.logout(opts);
192
+ if (opts.openUrl || opts.openUrl === false) {
334
193
  dispatch({ type: 'LOGOUT' });
335
194
  }
336
- return maybePromise;
337
195
  },
338
196
  [client]
339
197
  );
@@ -361,7 +219,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
361
219
  async (
362
220
  opts?: GetTokenWithPopupOptions,
363
221
  config?: PopupConfigOptions
364
- ): Promise<string> => {
222
+ ): Promise<string | undefined> => {
365
223
  let token;
366
224
  try {
367
225
  token = await client.getTokenWithPopup(opts, config);
@@ -379,7 +237,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
379
237
  );
380
238
 
381
239
  const getIdTokenClaims = useCallback(
382
- (opts) => client.getIdTokenClaims(opts),
240
+ () => client.getIdTokenClaims(),
383
241
  [client]
384
242
  );
385
243
 
@@ -402,8 +260,6 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
402
260
  const contextValue = useMemo(() => {
403
261
  return {
404
262
  ...state,
405
- buildAuthorizeUrl,
406
- buildLogoutUrl,
407
263
  getAccessTokenSilently,
408
264
  getAccessTokenWithPopup,
409
265
  getIdTokenClaims,
@@ -414,8 +270,6 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
414
270
  };
415
271
  }, [
416
272
  state,
417
- buildAuthorizeUrl,
418
- buildLogoutUrl,
419
273
  getAccessTokenSilently,
420
274
  getAccessTokenWithPopup,
421
275
  getIdTokenClaims,
package/src/index.tsx CHANGED
@@ -13,14 +13,14 @@ export {
13
13
  default as Auth0Context,
14
14
  Auth0ContextInterface,
15
15
  initialContext,
16
+ LogoutOptions,
16
17
  RedirectLoginOptions,
17
18
  } from './auth0-context';
18
19
  export {
20
+ AuthorizationParams,
19
21
  PopupLoginOptions,
20
22
  PopupConfigOptions,
21
- GetIdTokenClaimsOptions,
22
23
  GetTokenWithPopupOptions,
23
- LogoutOptions,
24
24
  LogoutUrlOptions,
25
25
  CacheLocation,
26
26
  GetTokenSilentlyOptions,
package/src/reducer.tsx CHANGED
@@ -35,7 +35,7 @@ export const reducer = (state: AuthState, action: Action): AuthState => {
35
35
  };
36
36
  case 'HANDLE_REDIRECT_COMPLETE':
37
37
  case 'GET_ACCESS_TOKEN_COMPLETE':
38
- if (state.user?.updated_at === action.user?.updated_at) {
38
+ if (state.user === action.user) {
39
39
  return state;
40
40
  }
41
41
  return {
@@ -1,7 +1,9 @@
1
1
  import React, { ComponentType, useEffect, FC } from 'react';
2
- import { RedirectLoginOptions, User } from '@auth0/auth0-spa-js';
3
2
  import useAuth0 from './use-auth0';
4
- import Auth0Context, { Auth0ContextInterface } from './auth0-context';
3
+ import Auth0Context, {
4
+ Auth0ContextInterface,
5
+ RedirectLoginOptions,
6
+ } from './auth0-context';
5
7
 
6
8
  /**
7
9
  * @ignore
@@ -61,12 +63,6 @@ export interface WithAuthenticationRequiredOptions {
61
63
  * This will be merged with the `returnTo` option used by the `onRedirectCallback` handler.
62
64
  */
63
65
  loginOptions?: RedirectLoginOptions;
64
- /**
65
- * Check the user object for JWT claims and return a boolean indicating
66
- * whether or not they are authorized to view the component.
67
- */
68
- claimCheck?: (claims?: User) => boolean;
69
-
70
66
  /**
71
67
  * The context to be used when calling useAuth0, this should only be provided if you are using multiple Auth0Providers
72
68
  * within your application and you wish to tie a specific component to a Auth0Provider other than the Auth0Provider
@@ -91,22 +87,15 @@ const withAuthenticationRequired = <P extends object>(
91
87
  const {
92
88
  returnTo = defaultReturnTo,
93
89
  onRedirecting = defaultOnRedirecting,
94
- claimCheck = (): boolean => true,
95
90
  loginOptions,
96
91
  context = Auth0Context,
97
92
  } = options;
98
93
 
99
- const { user, isAuthenticated, isLoading, loginWithRedirect } =
94
+ const { isAuthenticated, isLoading, loginWithRedirect } =
100
95
  useAuth0(context);
101
96
 
102
- /**
103
- * The route is authenticated if the user has valid auth and there are no
104
- * JWT claim mismatches.
105
- */
106
- const routeIsAuthenticated = isAuthenticated && claimCheck(user);
107
-
108
97
  useEffect(() => {
109
- if (isLoading || routeIsAuthenticated) {
98
+ if (isLoading || isAuthenticated) {
110
99
  return;
111
100
  }
112
101
  const opts = {
@@ -121,13 +110,13 @@ const withAuthenticationRequired = <P extends object>(
121
110
  })();
122
111
  }, [
123
112
  isLoading,
124
- routeIsAuthenticated,
113
+ isAuthenticated,
125
114
  loginWithRedirect,
126
115
  loginOptions,
127
116
  returnTo,
128
117
  ]);
129
118
 
130
- return routeIsAuthenticated ? <Component {...props} /> : onRedirecting();
119
+ return isAuthenticated ? <Component {...props} /> : onRedirecting();
131
120
  };
132
121
  };
133
122