@auth0/auth0-react 1.10.0 → 1.11.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.
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,UAAW,SAAQ,KAAK;IAChB,KAAK,EAAE,MAAM;IAAS,iBAAiB,CAAC;gBAAxC,KAAK,EAAE,MAAM,EAAS,iBAAiB,CAAC,oBAAQ;CAGpE"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,UAAW,SAAQ,KAAK;IAChB,KAAK,EAAE,MAAM;IAAS,iBAAiB,CAAC;gBAAxC,KAAK,EAAE,MAAM,EAAS,iBAAiB,CAAC,oBAAQ;CAMpE"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Auth0",
3
3
  "name": "@auth0/auth0-react",
4
- "version": "1.10.0",
4
+ "version": "1.11.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.0.0",
78
- "react-dom": "^18.0.0",
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.21.0"
103
+ "@auth0/auth0-spa-js": "^1.22.2"
106
104
  }
107
105
  }
@@ -3,6 +3,7 @@ import React, {
3
3
  useEffect,
4
4
  useMemo,
5
5
  useReducer,
6
+ useRef,
6
7
  useState,
7
8
  } from 'react';
8
9
  import {
@@ -18,6 +19,7 @@ import {
18
19
  RedirectLoginResult,
19
20
  ICache,
20
21
  GetTokenSilentlyOptions,
22
+ User,
21
23
  } from '@auth0/auth0-spa-js';
22
24
  import Auth0Context, { RedirectLoginOptions } from './auth0-context';
23
25
  import { hasAuthParams, loginError, tokenError } from './utils';
@@ -45,7 +47,7 @@ export interface Auth0ProviderOptions {
45
47
  * It uses `window.history` but you might want to overwrite this if you are using a custom router, like `react-router-dom`
46
48
  * See the EXAMPLES.md for more info.
47
49
  */
48
- onRedirectCallback?: (appState?: AppState) => void;
50
+ onRedirectCallback?: (appState?: AppState, user?: User) => void;
49
51
  /**
50
52
  * By default, if the page url has code/state params, the SDK will treat them as Auth0's and attempt to exchange the
51
53
  * code for a token. In some cases the code might be for something else (another OAuth SDK perhaps). In these
@@ -240,17 +242,24 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
240
242
  () => new Auth0Client(toAuth0ClientOptions(clientOpts))
241
243
  );
242
244
  const [state, dispatch] = useReducer(reducer, initialAuthState);
245
+ const didInitialise = useRef(false);
243
246
 
244
247
  useEffect(() => {
248
+ if (didInitialise.current) {
249
+ return;
250
+ }
251
+ didInitialise.current = true;
245
252
  (async (): Promise<void> => {
246
253
  try {
254
+ let user: User | undefined;
247
255
  if (hasAuthParams() && !skipRedirectCallback) {
248
256
  const { appState } = await client.handleRedirectCallback();
249
- onRedirectCallback(appState);
257
+ user = await client.getUser();
258
+ onRedirectCallback(appState, user);
250
259
  } else {
251
260
  await client.checkSession();
261
+ user = await client.getUser();
252
262
  }
253
- const user = await client.getUser();
254
263
  dispatch({ type: 'INITIALISED', user });
255
264
  } catch (error) {
256
265
  dispatch({ type: 'ERROR', error: loginError(error) });
package/src/errors.tsx CHANGED
@@ -7,5 +7,8 @@
7
7
  export class OAuthError extends Error {
8
8
  constructor(public error: string, public error_description?: string) {
9
9
  super(error_description || error);
10
+
11
+ // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
12
+ Object.setPrototypeOf(this, OAuthError.prototype);
10
13
  }
11
14
  }