@auth0/auth0-react 2.0.0 → 2.0.2

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":"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
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.tsx"],"names":[],"mappings":"AAMA,eAAO,MAAM,aAAa,6BAA4C,OAEzC,CAAC;AA0B9B,eAAO,MAAM,UAAU,UAtBb,OAAO,KAAG,KAsBsC,CAAC;AAE3D,eAAO,MAAM,UAAU,UAxBb,OAAO,KAAG,KAwBiD,CAAC;AAEtE;;;;GAIG;AAEH,eAAO,MAAM,oBAAoB,aAAc,GAAG,SAkBjD,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Auth0",
3
3
  "name": "@auth0/auth0-react",
4
- "version": "2.0.0",
4
+ "version": "2.0.2",
5
5
  "description": "Auth0 SDK for React Single Page Applications (SPA)",
6
6
  "keywords": [
7
7
  "auth0",
@@ -67,7 +67,7 @@
67
67
  "eslint": "^8.28.0",
68
68
  "eslint-plugin-react": "^7.31.11",
69
69
  "eslint-plugin-react-hooks": "^4.6.0",
70
- "husky": "^4.3.8",
70
+ "husky": "^8.0.3",
71
71
  "jest": "^29.3.1",
72
72
  "jest-environment-jsdom": "^29.3.1",
73
73
  "jest-junit": "^15.0.0",
@@ -95,12 +95,7 @@
95
95
  "react": "^16.11.0 || ^17 || ^18",
96
96
  "react-dom": "^16.11.0 || ^17 || ^18"
97
97
  },
98
- "husky": {
99
- "hooks": {
100
- "pre-commit": "pretty-quick --staged"
101
- }
102
- },
103
98
  "dependencies": {
104
- "@auth0/auth0-spa-js": "^2.0.2"
99
+ "@auth0/auth0-spa-js": "^2.0.4"
105
100
  }
106
101
  }
@@ -21,7 +21,12 @@ import Auth0Context, {
21
21
  LogoutOptions,
22
22
  RedirectLoginOptions,
23
23
  } from './auth0-context';
24
- import { hasAuthParams, loginError, tokenError } from './utils';
24
+ import {
25
+ hasAuthParams,
26
+ loginError,
27
+ tokenError,
28
+ deprecateRedirectUri,
29
+ } from './utils';
25
30
  import { reducer } from './reducer';
26
31
  import { initialAuthState } from './auth-state';
27
32
 
@@ -93,6 +98,8 @@ declare const __VERSION__: string;
93
98
  const toAuth0ClientOptions = (
94
99
  opts: Auth0ProviderOptions
95
100
  ): Auth0ClientOptions => {
101
+ deprecateRedirectUri(opts);
102
+
96
103
  return {
97
104
  ...opts,
98
105
  auth0Client: {
@@ -118,7 +125,7 @@ const defaultOnRedirectCallback = (appState?: AppState): void => {
118
125
  * <Auth0Provider
119
126
  * domain={domain}
120
127
  * clientId={clientId}
121
- * redirectUri={window.location.origin}>
128
+ * authorizationParams={{ redirect_uri: window.location.origin }}}>
122
129
  * <MyApp />
123
130
  * </Auth0Provider>
124
131
  * ```
@@ -163,8 +170,11 @@ const Auth0Provider = (opts: Auth0ProviderOptions): JSX.Element => {
163
170
  }, [client, onRedirectCallback, skipRedirectCallback]);
164
171
 
165
172
  const loginWithRedirect = useCallback(
166
- (opts?: RedirectLoginOptions): Promise<void> =>
167
- client.loginWithRedirect(opts),
173
+ (opts?: RedirectLoginOptions): Promise<void> => {
174
+ deprecateRedirectUri(opts);
175
+
176
+ return client.loginWithRedirect(opts);
177
+ },
168
178
  [client]
169
179
  );
170
180
 
package/src/utils.tsx CHANGED
@@ -8,18 +8,56 @@ export const hasAuthParams = (searchParams = window.location.search): boolean =>
8
8
  (CODE_RE.test(searchParams) || ERROR_RE.test(searchParams)) &&
9
9
  STATE_RE.test(searchParams);
10
10
 
11
- const normalizeErrorFn = (fallbackMessage: string) => (
12
- error: Error | { error: string; error_description?: string } | ProgressEvent
13
- ): Error => {
14
- if ('error' in error) {
15
- return new OAuthError(error.error, error.error_description);
16
- }
17
- if (error instanceof Error) {
18
- return error;
19
- }
20
- return new Error(fallbackMessage);
21
- };
11
+ const normalizeErrorFn =
12
+ (fallbackMessage: string) =>
13
+ (error: unknown): Error => {
14
+ if (error instanceof Error) {
15
+ return error;
16
+ }
17
+ // try to check errors of the following form: {error: string; error_description?: string}
18
+ if (
19
+ error !== null &&
20
+ typeof error === 'object' &&
21
+ 'error' in error &&
22
+ typeof error.error === 'string'
23
+ ) {
24
+ if (
25
+ 'error_description' in error &&
26
+ typeof error.error_description === 'string'
27
+ ) {
28
+ return new OAuthError(error.error, error.error_description);
29
+ }
30
+ return new OAuthError(error.error);
31
+ }
32
+ return new Error(fallbackMessage);
33
+ };
22
34
 
23
35
  export const loginError = normalizeErrorFn('Login failed');
24
36
 
25
37
  export const tokenError = normalizeErrorFn('Get access token failed');
38
+
39
+ /**
40
+ * @ignore
41
+ * Helper function to map the v1 `redirectUri` option to the v2 `authorizationParams.redirect_uri`
42
+ * and log a warning.
43
+ */
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
+ export const deprecateRedirectUri = (options?: any) => {
46
+ if (options?.redirectUri) {
47
+ console.warn(
48
+ 'Using `redirectUri` has been deprecated, please use `authorizationParams.redirect_uri` instead as `redirectUri` will be no longer supported in a future version'
49
+ );
50
+ options.authorizationParams = options.authorizationParams || {};
51
+ options.authorizationParams.redirect_uri = options.redirectUri;
52
+ delete options.redirectUri;
53
+ }
54
+
55
+ if (options?.authorizationParams?.redirectUri) {
56
+ console.warn(
57
+ 'Using `authorizationParams.redirectUri` has been deprecated, please use `authorizationParams.redirect_uri` instead as `authorizationParams.redirectUri` will be removed in a future version'
58
+ );
59
+ options.authorizationParams.redirect_uri =
60
+ options.authorizationParams.redirectUri;
61
+ delete options.authorizationParams.redirectUri;
62
+ }
63
+ };