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