@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/auth0-react.js
CHANGED
|
@@ -150,12 +150,20 @@
|
|
|
150
150
|
};
|
|
151
151
|
var normalizeErrorFn = function (fallbackMessage) {
|
|
152
152
|
return function (error) {
|
|
153
|
-
if ('error' in error) {
|
|
154
|
-
return new OAuthError(error.error, error.error_description);
|
|
155
|
-
}
|
|
156
153
|
if (error instanceof Error) {
|
|
157
154
|
return error;
|
|
158
155
|
}
|
|
156
|
+
// try to check errors of the following form: {error: string; error_description?: string}
|
|
157
|
+
if (error !== null &&
|
|
158
|
+
typeof error === 'object' &&
|
|
159
|
+
'error' in error &&
|
|
160
|
+
typeof error.error === 'string') {
|
|
161
|
+
if ('error_description' in error &&
|
|
162
|
+
typeof error.error_description === 'string') {
|
|
163
|
+
return new OAuthError(error.error, error.error_description);
|
|
164
|
+
}
|
|
165
|
+
return new OAuthError(error.error);
|
|
166
|
+
}
|
|
159
167
|
return new Error(fallbackMessage);
|
|
160
168
|
};
|
|
161
169
|
};
|
|
@@ -213,7 +221,7 @@
|
|
|
213
221
|
deprecateRedirectUri(opts);
|
|
214
222
|
return __assign(__assign({}, opts), { auth0Client: {
|
|
215
223
|
name: 'auth0-react',
|
|
216
|
-
version: '2.0
|
|
224
|
+
version: '2.1.0',
|
|
217
225
|
} });
|
|
218
226
|
};
|
|
219
227
|
/**
|
|
@@ -480,6 +488,12 @@
|
|
|
480
488
|
* @ignore
|
|
481
489
|
*/
|
|
482
490
|
var defaultOnRedirecting = function () { return React.createElement(React.Fragment, null); };
|
|
491
|
+
/**
|
|
492
|
+
* @ignore
|
|
493
|
+
*/
|
|
494
|
+
var defaultOnBeforeAuthentication = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
495
|
+
return [2 /*return*/];
|
|
496
|
+
}); }); };
|
|
483
497
|
/**
|
|
484
498
|
* @ignore
|
|
485
499
|
*/
|
|
@@ -498,8 +512,8 @@
|
|
|
498
512
|
if (options === void 0) { options = {}; }
|
|
499
513
|
return function WithAuthenticationRequired(props) {
|
|
500
514
|
var _this = this;
|
|
501
|
-
var _a = options.returnTo, returnTo = _a === void 0 ? defaultReturnTo : _a, _b = options.onRedirecting, onRedirecting = _b === void 0 ? defaultOnRedirecting : _b, loginOptions = options.loginOptions,
|
|
502
|
-
var
|
|
515
|
+
var _a = options.returnTo, returnTo = _a === void 0 ? defaultReturnTo : _a, _b = options.onRedirecting, onRedirecting = _b === void 0 ? defaultOnRedirecting : _b, _c = options.onBeforeAuthentication, onBeforeAuthentication = _c === void 0 ? defaultOnBeforeAuthentication : _c, loginOptions = options.loginOptions, _d = options.context, context = _d === void 0 ? Auth0Context : _d;
|
|
516
|
+
var _e = useAuth0(context), isAuthenticated = _e.isAuthenticated, isLoading = _e.isLoading, loginWithRedirect = _e.loginWithRedirect;
|
|
503
517
|
React.useEffect(function () {
|
|
504
518
|
if (isLoading || isAuthenticated) {
|
|
505
519
|
return;
|
|
@@ -508,8 +522,11 @@
|
|
|
508
522
|
(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
509
523
|
return __generator(this, function (_a) {
|
|
510
524
|
switch (_a.label) {
|
|
511
|
-
case 0: return [4 /*yield*/,
|
|
525
|
+
case 0: return [4 /*yield*/, onBeforeAuthentication()];
|
|
512
526
|
case 1:
|
|
527
|
+
_a.sent();
|
|
528
|
+
return [4 /*yield*/, loginWithRedirect(opts)];
|
|
529
|
+
case 2:
|
|
513
530
|
_a.sent();
|
|
514
531
|
return [2 /*return*/];
|
|
515
532
|
}
|
|
@@ -519,6 +536,7 @@
|
|
|
519
536
|
isLoading,
|
|
520
537
|
isAuthenticated,
|
|
521
538
|
loginWithRedirect,
|
|
539
|
+
onBeforeAuthentication,
|
|
522
540
|
loginOptions,
|
|
523
541
|
returnTo,
|
|
524
542
|
]);
|