@auth0/auth0-react 2.0.1 → 2.1.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/auth0-react.cjs.js +25 -7
- package/dist/auth0-react.cjs.js.map +1 -1
- package/dist/auth0-react.esm.js +25 -7
- package/dist/auth0-react.esm.js.map +1 -1
- package/dist/auth0-react.js +25 -7
- package/dist/auth0-react.js.map +1 -1
- package/dist/auth0-react.min.js +1 -1
- package/dist/auth0-react.min.js.map +1 -1
- package/dist/utils.d.ts +2 -8
- package/dist/utils.d.ts.map +1 -1
- package/dist/with-authentication-required.d.ts +10 -0
- package/dist/with-authentication-required.d.ts.map +1 -1
- package/package.json +2 -7
- package/src/utils.tsx +16 -6
- package/src/with-authentication-required.tsx +18 -0
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.tsx"],"names":[],"mappings":"AAMA,eAAO,MAAM,aAAa,6BAA4C,OAEzC,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"}
|
|
@@ -32,6 +32,16 @@ export interface WithAuthenticationRequiredOptions {
|
|
|
32
32
|
* Render a message to show that the user is being redirected to the login.
|
|
33
33
|
*/
|
|
34
34
|
onRedirecting?: () => JSX.Element;
|
|
35
|
+
/**
|
|
36
|
+
* ```js
|
|
37
|
+
* withAuthenticationRequired(Profile, {
|
|
38
|
+
* onBeforeAuthentication: () => { analyticsLibrary.track('login_triggered'); }
|
|
39
|
+
* })
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* Allows executing logic before the user is redirected to the login page.
|
|
43
|
+
*/
|
|
44
|
+
onBeforeAuthentication?: () => Promise<void>;
|
|
35
45
|
/**
|
|
36
46
|
* ```js
|
|
37
47
|
* withAuthenticationRequired(Profile, {
|
|
@@ -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;AAE5D,OAAqB,EACnB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,iBAAiB,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;AAkBzB;;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;;;;;;;;OAQG;IACH,sBAAsB,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C;;;;;;;;;;;;;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,gBAwC3C,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": "2.0
|
|
4
|
+
"version": "2.1.0",
|
|
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": "^
|
|
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,11 +95,6 @@
|
|
|
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
99
|
"@auth0/auth0-spa-js": "^2.0.4"
|
|
105
100
|
}
|
package/src/utils.tsx
CHANGED
|
@@ -10,15 +10,25 @@ export const hasAuthParams = (searchParams = window.location.search): boolean =>
|
|
|
10
10
|
|
|
11
11
|
const normalizeErrorFn =
|
|
12
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
|
-
}
|
|
13
|
+
(error: unknown): Error => {
|
|
19
14
|
if (error instanceof Error) {
|
|
20
15
|
return error;
|
|
21
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
|
+
}
|
|
22
32
|
return new Error(fallbackMessage);
|
|
23
33
|
};
|
|
24
34
|
|
|
@@ -10,6 +10,11 @@ import Auth0Context, {
|
|
|
10
10
|
*/
|
|
11
11
|
const defaultOnRedirecting = (): JSX.Element => <></>;
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* @ignore
|
|
15
|
+
*/
|
|
16
|
+
const defaultOnBeforeAuthentication = async (): Promise<void> => {/* noop */};
|
|
17
|
+
|
|
13
18
|
/**
|
|
14
19
|
* @ignore
|
|
15
20
|
*/
|
|
@@ -48,6 +53,16 @@ export interface WithAuthenticationRequiredOptions {
|
|
|
48
53
|
* Render a message to show that the user is being redirected to the login.
|
|
49
54
|
*/
|
|
50
55
|
onRedirecting?: () => JSX.Element;
|
|
56
|
+
/**
|
|
57
|
+
* ```js
|
|
58
|
+
* withAuthenticationRequired(Profile, {
|
|
59
|
+
* onBeforeAuthentication: () => { analyticsLibrary.track('login_triggered'); }
|
|
60
|
+
* })
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* Allows executing logic before the user is redirected to the login page.
|
|
64
|
+
*/
|
|
65
|
+
onBeforeAuthentication?: () => Promise<void>;
|
|
51
66
|
/**
|
|
52
67
|
* ```js
|
|
53
68
|
* withAuthenticationRequired(Profile, {
|
|
@@ -87,6 +102,7 @@ const withAuthenticationRequired = <P extends object>(
|
|
|
87
102
|
const {
|
|
88
103
|
returnTo = defaultReturnTo,
|
|
89
104
|
onRedirecting = defaultOnRedirecting,
|
|
105
|
+
onBeforeAuthentication = defaultOnBeforeAuthentication,
|
|
90
106
|
loginOptions,
|
|
91
107
|
context = Auth0Context,
|
|
92
108
|
} = options;
|
|
@@ -106,12 +122,14 @@ const withAuthenticationRequired = <P extends object>(
|
|
|
106
122
|
},
|
|
107
123
|
};
|
|
108
124
|
(async (): Promise<void> => {
|
|
125
|
+
await onBeforeAuthentication();
|
|
109
126
|
await loginWithRedirect(opts);
|
|
110
127
|
})();
|
|
111
128
|
}, [
|
|
112
129
|
isLoading,
|
|
113
130
|
isAuthenticated,
|
|
114
131
|
loginWithRedirect,
|
|
132
|
+
onBeforeAuthentication,
|
|
115
133
|
loginOptions,
|
|
116
134
|
returnTo,
|
|
117
135
|
]);
|