@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.esm.js
CHANGED
|
@@ -146,12 +146,20 @@ var hasAuthParams = function (searchParams) {
|
|
|
146
146
|
};
|
|
147
147
|
var normalizeErrorFn = function (fallbackMessage) {
|
|
148
148
|
return function (error) {
|
|
149
|
-
if ('error' in error) {
|
|
150
|
-
return new OAuthError(error.error, error.error_description);
|
|
151
|
-
}
|
|
152
149
|
if (error instanceof Error) {
|
|
153
150
|
return error;
|
|
154
151
|
}
|
|
152
|
+
// try to check errors of the following form: {error: string; error_description?: string}
|
|
153
|
+
if (error !== null &&
|
|
154
|
+
typeof error === 'object' &&
|
|
155
|
+
'error' in error &&
|
|
156
|
+
typeof error.error === 'string') {
|
|
157
|
+
if ('error_description' in error &&
|
|
158
|
+
typeof error.error_description === 'string') {
|
|
159
|
+
return new OAuthError(error.error, error.error_description);
|
|
160
|
+
}
|
|
161
|
+
return new OAuthError(error.error);
|
|
162
|
+
}
|
|
155
163
|
return new Error(fallbackMessage);
|
|
156
164
|
};
|
|
157
165
|
};
|
|
@@ -209,7 +217,7 @@ var toAuth0ClientOptions = function (opts) {
|
|
|
209
217
|
deprecateRedirectUri(opts);
|
|
210
218
|
return __assign(__assign({}, opts), { auth0Client: {
|
|
211
219
|
name: 'auth0-react',
|
|
212
|
-
version: '2.0
|
|
220
|
+
version: '2.1.0',
|
|
213
221
|
} });
|
|
214
222
|
};
|
|
215
223
|
/**
|
|
@@ -476,6 +484,12 @@ var withAuth0 = function (Component, context) {
|
|
|
476
484
|
* @ignore
|
|
477
485
|
*/
|
|
478
486
|
var defaultOnRedirecting = function () { return React.createElement(React.Fragment, null); };
|
|
487
|
+
/**
|
|
488
|
+
* @ignore
|
|
489
|
+
*/
|
|
490
|
+
var defaultOnBeforeAuthentication = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
491
|
+
return [2 /*return*/];
|
|
492
|
+
}); }); };
|
|
479
493
|
/**
|
|
480
494
|
* @ignore
|
|
481
495
|
*/
|
|
@@ -494,8 +508,8 @@ var withAuthenticationRequired = function (Component, options) {
|
|
|
494
508
|
if (options === void 0) { options = {}; }
|
|
495
509
|
return function WithAuthenticationRequired(props) {
|
|
496
510
|
var _this = this;
|
|
497
|
-
var _a = options.returnTo, returnTo = _a === void 0 ? defaultReturnTo : _a, _b = options.onRedirecting, onRedirecting = _b === void 0 ? defaultOnRedirecting : _b, loginOptions = options.loginOptions,
|
|
498
|
-
var
|
|
511
|
+
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;
|
|
512
|
+
var _e = useAuth0(context), isAuthenticated = _e.isAuthenticated, isLoading = _e.isLoading, loginWithRedirect = _e.loginWithRedirect;
|
|
499
513
|
useEffect(function () {
|
|
500
514
|
if (isLoading || isAuthenticated) {
|
|
501
515
|
return;
|
|
@@ -504,8 +518,11 @@ var withAuthenticationRequired = function (Component, options) {
|
|
|
504
518
|
(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
505
519
|
return __generator(this, function (_a) {
|
|
506
520
|
switch (_a.label) {
|
|
507
|
-
case 0: return [4 /*yield*/,
|
|
521
|
+
case 0: return [4 /*yield*/, onBeforeAuthentication()];
|
|
508
522
|
case 1:
|
|
523
|
+
_a.sent();
|
|
524
|
+
return [4 /*yield*/, loginWithRedirect(opts)];
|
|
525
|
+
case 2:
|
|
509
526
|
_a.sent();
|
|
510
527
|
return [2 /*return*/];
|
|
511
528
|
}
|
|
@@ -515,6 +532,7 @@ var withAuthenticationRequired = function (Component, options) {
|
|
|
515
532
|
isLoading,
|
|
516
533
|
isAuthenticated,
|
|
517
534
|
loginWithRedirect,
|
|
535
|
+
onBeforeAuthentication,
|
|
518
536
|
loginOptions,
|
|
519
537
|
returnTo,
|
|
520
538
|
]);
|