@auth0/auth0-react 2.0.0-beta.0 → 2.0.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Auth0",
3
3
  "name": "@auth0/auth0-react",
4
- "version": "2.0.0-beta.0",
4
+ "version": "2.0.1",
5
5
  "description": "Auth0 SDK for React Single Page Applications (SPA)",
6
6
  "keywords": [
7
7
  "auth0",
@@ -101,6 +101,6 @@
101
101
  }
102
102
  },
103
103
  "dependencies": {
104
- "@auth0/auth0-spa-js": "^2.0.1"
104
+ "@auth0/auth0-spa-js": "^2.0.4"
105
105
  }
106
106
  }
@@ -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,46 @@ 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
+ (
14
+ error: Error | { error: string; error_description?: string } | ProgressEvent
15
+ ): Error => {
16
+ if ('error' in error) {
17
+ return new OAuthError(error.error, error.error_description);
18
+ }
19
+ if (error instanceof Error) {
20
+ return error;
21
+ }
22
+ return new Error(fallbackMessage);
23
+ };
22
24
 
23
25
  export const loginError = normalizeErrorFn('Login failed');
24
26
 
25
27
  export const tokenError = normalizeErrorFn('Get access token failed');
28
+
29
+ /**
30
+ * @ignore
31
+ * Helper function to map the v1 `redirectUri` option to the v2 `authorizationParams.redirect_uri`
32
+ * and log a warning.
33
+ */
34
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
+ export const deprecateRedirectUri = (options?: any) => {
36
+ if (options?.redirectUri) {
37
+ console.warn(
38
+ 'Using `redirectUri` has been deprecated, please use `authorizationParams.redirect_uri` instead as `redirectUri` will be no longer supported in a future version'
39
+ );
40
+ options.authorizationParams = options.authorizationParams || {};
41
+ options.authorizationParams.redirect_uri = options.redirectUri;
42
+ delete options.redirectUri;
43
+ }
44
+
45
+ if (options?.authorizationParams?.redirectUri) {
46
+ console.warn(
47
+ 'Using `authorizationParams.redirectUri` has been deprecated, please use `authorizationParams.redirect_uri` instead as `authorizationParams.redirectUri` will be removed in a future version'
48
+ );
49
+ options.authorizationParams.redirect_uri =
50
+ options.authorizationParams.redirectUri;
51
+ delete options.authorizationParams.redirectUri;
52
+ }
53
+ };