@asgardeo/react 0.2.1 → 0.2.3

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.
@@ -24,6 +24,7 @@ interface AuthContext {
24
24
  isAuthLoading: boolean;
25
25
  isAuthenticated: boolean | undefined;
26
26
  isBrandingLoading: boolean;
27
+ isComponentLoading: boolean;
27
28
  isGlobalLoading: boolean;
28
29
  isTextLoading: boolean;
29
30
  onSignOutRef: React.MutableRefObject<Function>;
@@ -31,6 +32,7 @@ interface AuthContext {
31
32
  setAuthentication: () => void;
32
33
  setIsAuthLoading: (value: boolean) => void;
33
34
  setIsBrandingLoading: (value: boolean) => void;
35
+ setIsComponentLoading: (value: boolean) => void;
34
36
  setIsTextLoading: (value: boolean) => void;
35
37
  setOnSignIn: (response?: any) => void | Promise<void>;
36
38
  setOnSignOut: (response?: any) => void | Promise<void>;
@@ -20,6 +20,7 @@ interface UseAuthentication {
20
20
  accessToken: string;
21
21
  authResponse: AuthApiResponse;
22
22
  isAuthenticated: Promise<boolean> | boolean;
23
+ isGlobalLoading: boolean;
23
24
  setUsername: (username: string) => void;
24
25
  signOut: () => void;
25
26
  user: MeAPIResponse;
package/dist/esm/index.js CHANGED
@@ -39979,13 +39979,18 @@ const I18nContext = createContext(undefined);
39979
39979
  const useTranslations = (props) => {
39980
39980
  const { componentLocaleOverride, componentTextOverrides, screen } = props;
39981
39981
  const [isLoading, setIsLoading] = useState(true);
39982
+ const { setIsTextLoading } = useContext(AsgardeoContext);
39982
39983
  const contextValue = useContext(I18nContext);
39983
39984
  const { text, setTranslations } = contextValue;
39984
39985
  useEffect(() => {
39985
39986
  setTranslations({ componentLocaleOverride, componentTextOverrides, screen }).then((response) => {
39986
39987
  setIsLoading(!response);
39988
+ setIsTextLoading(!response);
39987
39989
  });
39988
39990
  }, [componentLocaleOverride, componentTextOverrides, screen, setTranslations]);
39991
+ useEffect(() => {
39992
+ setIsTextLoading(isLoading);
39993
+ }, [isLoading]);
39989
39994
  /**
39990
39995
  * `t` is a function that retrieves a specific translation from the fetched translations.
39991
39996
  * It takes a key as an argument, which is a string that represents a path to the desired translation.
@@ -40488,7 +40493,7 @@ const BrandingPreferenceContext = createContext(undefined);
40488
40493
  */
40489
40494
  const useAuthentication = () => {
40490
40495
  const contextValue = useContext(AsgardeoContext);
40491
- const { accessToken, authResponse, isAuthenticated, setUsername, user, username } = contextValue;
40496
+ const { accessToken, authResponse, isAuthenticated, isGlobalLoading, setUsername, user, username } = contextValue;
40492
40497
  const signOut$1 = () => {
40493
40498
  signOut().then(() => {
40494
40499
  sessionStorage.clear();
@@ -40501,6 +40506,7 @@ const useAuthentication = () => {
40501
40506
  accessToken,
40502
40507
  authResponse,
40503
40508
  isAuthenticated,
40509
+ isGlobalLoading,
40504
40510
  setUsername,
40505
40511
  signOut: signOut$1,
40506
40512
  user,
@@ -44427,7 +44433,6 @@ const IdentifierFirst = ({ handleAuthenticate, authenticator, alert, brandingPro
44427
44433
  const SignIn = (props) => {
44428
44434
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
44429
44435
  const { basicAuthChildren, brandingProps, emailOtpChildren, identifierFirstChildren, showFooter = true, showLogo = true, showSignUp, smsOtpChildren, totpChildren, } = props;
44430
- const [isComponentLoading, setIsComponentLoading] = useState(true);
44431
44436
  const [alert, setAlert] = useState();
44432
44437
  const [showSelfSignUp, setShowSelfSignUp] = useState(showSignUp);
44433
44438
  const [componentBranding, setComponentBranding] = useState();
@@ -44452,12 +44457,13 @@ const SignIn = (props) => {
44452
44457
  authorize()
44453
44458
  .then((response) => {
44454
44459
  authContext === null || authContext === void 0 ? void 0 : authContext.setAuthResponse(response);
44455
- setIsComponentLoading(false);
44456
44460
  })
44457
44461
  .catch((error) => {
44458
44462
  setAlert({ alertType: { error: true }, key: keys.common.error });
44459
- setIsComponentLoading(false);
44460
44463
  throw new AsgardeoUIException('REACT_UI-SIGN_IN-SI-SE01', 'Authorization failed', error.stack);
44464
+ })
44465
+ .finally(() => {
44466
+ authContext === null || authContext === void 0 ? void 0 : authContext.setIsComponentLoading(false);
44461
44467
  });
44462
44468
  }, []);
44463
44469
  /**
@@ -44471,7 +44477,7 @@ const SignIn = (props) => {
44471
44477
  if ((authContext === null || authContext === void 0 ? void 0 : authContext.authResponse) === undefined) {
44472
44478
  throw new AsgardeoUIException('REACT_UI-SIGN_IN-HA-IV02', 'Auth response is undefined.');
44473
44479
  }
44474
- authContext.setIsAuthLoading(true);
44480
+ authContext === null || authContext === void 0 ? void 0 : authContext.setIsAuthLoading(true);
44475
44481
  const resp = yield authenticate({
44476
44482
  flowId: authContext === null || authContext === void 0 ? void 0 : authContext.authResponse.flowId,
44477
44483
  selectedAuthenticator: {
@@ -44480,7 +44486,7 @@ const SignIn = (props) => {
44480
44486
  },
44481
44487
  }).catch((authnError) => {
44482
44488
  setAlert({ alertType: { error: true }, key: keys.common.error });
44483
- authContext.setIsAuthLoading(false);
44489
+ authContext === null || authContext === void 0 ? void 0 : authContext.setIsAuthLoading(false);
44484
44490
  throw new AsgardeoUIException('REACT_UI-SIGN_IN-HA-SE03', 'Authentication failed.', authnError.stack);
44485
44491
  });
44486
44492
  if (!authParams) {
@@ -44522,7 +44528,7 @@ const SignIn = (props) => {
44522
44528
  const authInstance = AuthClient.getInstance();
44523
44529
  const state = (yield authInstance.getDataLayer().getTemporaryDataParameter('state')).toString();
44524
44530
  yield authInstance.requestAccessToken(resp.authData.code, resp.authData.session_state, state);
44525
- authContext.setAuthentication();
44531
+ authContext === null || authContext === void 0 ? void 0 : authContext.setAuthentication();
44526
44532
  }
44527
44533
  else if (resp.flowStatus === FlowStatus.FailIncomplete) {
44528
44534
  authContext === null || authContext === void 0 ? void 0 : authContext.setAuthResponse(Object.assign(Object.assign({}, resp), { nextStep: authContext === null || authContext === void 0 ? void 0 : authContext.authResponse.nextStep }));
@@ -44532,13 +44538,13 @@ const SignIn = (props) => {
44532
44538
  authContext === null || authContext === void 0 ? void 0 : authContext.setAuthResponse(resp);
44533
44539
  setShowSelfSignUp(false);
44534
44540
  }
44535
- authContext.setIsAuthLoading(false);
44541
+ authContext === null || authContext === void 0 ? void 0 : authContext.setIsAuthLoading(false);
44536
44542
  });
44537
44543
  const renderLoginOptions = (authenticators) => {
44538
44544
  const LoginOptions = [];
44539
44545
  authenticators.forEach((authenticator) => {
44540
44546
  const displayName = authenticator.idp === 'LOCAL' ? authenticator.authenticator : authenticator.idp;
44541
- LoginOptions.push(jsxRuntimeExports.jsx(LoginOptionsBox, { isAuthLoading: authContext.isAuthLoading, socialName: authenticator.authenticator, displayName: `${t(keys.common.multiple.options.prefix)} ${displayName}`, handleOnClick: () => handleAuthenticate(authenticator.authenticatorId) }, authenticator.authenticatorId));
44547
+ LoginOptions.push(jsxRuntimeExports.jsx(LoginOptionsBox, { isAuthLoading: authContext === null || authContext === void 0 ? void 0 : authContext.isAuthLoading, socialName: authenticator.authenticator, displayName: `${t(keys.common.multiple.options.prefix)} ${displayName}`, handleOnClick: () => handleAuthenticate(authenticator.authenticatorId) }, authenticator.authenticatorId));
44542
44548
  });
44543
44549
  return LoginOptions;
44544
44550
  };
@@ -44585,7 +44591,7 @@ const SignIn = (props) => {
44585
44591
  /**
44586
44592
  * Renders the circular progress component while the component or text is loading.
44587
44593
  */
44588
- if (isComponentLoading || isLoading || authContext.isBrandingLoading) {
44594
+ if ((authContext === null || authContext === void 0 ? void 0 : authContext.isComponentLoading) || isLoading || (authContext === null || authContext === void 0 ? void 0 : authContext.isBrandingLoading)) {
44589
44595
  return (jsxRuntimeExports.jsx("div", { className: "Box-circularProgressHolder", children: jsxRuntimeExports.jsx(ae, { className: "circular-progress" }) }));
44590
44596
  }
44591
44597
  const imgUrl = (_f = (_e = (_d = (_c = (_b = brandingPreference === null || brandingPreference === void 0 ? void 0 : brandingPreference.preference) === null || _b === void 0 ? void 0 : _b.theme) === null || _c === void 0 ? void 0 : _c.LIGHT) === null || _d === void 0 ? void 0 : _d.images) === null || _e === void 0 ? void 0 : _e.logo) === null || _f === void 0 ? void 0 : _f.imgURL;
@@ -44594,7 +44600,7 @@ const SignIn = (props) => {
44594
44600
  if (showFooter && copyrightText.includes('{{currentYear}}')) {
44595
44601
  copyrightText = copyrightText.replace('{{currentYear}}', new Date().getFullYear().toString());
44596
44602
  }
44597
- return (jsxRuntimeExports.jsx(eo, { theme: generateThemeSignIn(componentBranding === null || componentBranding === void 0 ? void 0 : componentBranding.preference.theme), children: jsxRuntimeExports.jsxs(SignIn$1, { className: "Box-asgardeoSignIn", children: [showLogo && !(isLoading || isComponentLoading) && (jsxRuntimeExports.jsx(SignIn$1.Image, { className: "asgardeo-sign-in-logo", src: imgUrl })), ((_g = authContext === null || authContext === void 0 ? void 0 : authContext.authResponse) === null || _g === void 0 ? void 0 : _g.flowStatus) !== FlowStatus.SuccessCompleted && !isAuthenticated && (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [renderSignIn(), showFooter && !(isLoading || isComponentLoading) && (jsxRuntimeExports.jsx(SignIn$1.Footer, { className: "asgardeo-sign-in-footer", copyrights: { children: copyrightText }, items: [
44603
+ return (jsxRuntimeExports.jsx(eo, { theme: generateThemeSignIn(componentBranding === null || componentBranding === void 0 ? void 0 : componentBranding.preference.theme), children: jsxRuntimeExports.jsxs(SignIn$1, { className: "Box-asgardeoSignIn", children: [showLogo && !(isLoading || (authContext === null || authContext === void 0 ? void 0 : authContext.isComponentLoading)) && (jsxRuntimeExports.jsx(SignIn$1.Image, { className: "asgardeo-sign-in-logo", src: imgUrl })), ((_g = authContext === null || authContext === void 0 ? void 0 : authContext.authResponse) === null || _g === void 0 ? void 0 : _g.flowStatus) !== FlowStatus.SuccessCompleted && !isAuthenticated && (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [renderSignIn(), showFooter && !(isLoading || (authContext === null || authContext === void 0 ? void 0 : authContext.isComponentLoading)) && (jsxRuntimeExports.jsx(SignIn$1.Footer, { className: "asgardeo-sign-in-footer", copyrights: { children: copyrightText }, items: [
44598
44604
  {
44599
44605
  children: (jsxRuntimeExports.jsx(SignIn$1.Link, { href: componentBranding.preference.urls.privacyPolicyURL, children: t(keys.common.privacy.policy) })),
44600
44606
  },
@@ -45013,6 +45019,7 @@ const AsgardeoProvider = (props) => {
45013
45019
  const [isBrandingLoading, setIsBrandingLoading] = useState(true);
45014
45020
  const [isTextLoading, setIsTextLoading] = useState(true);
45015
45021
  const [isAuthLoading, setIsAuthLoading] = useState(false);
45022
+ const [isComponentLoading, setIsComponentLoading] = useState(true);
45016
45023
  const [authResponse, setAuthResponse] = useState();
45017
45024
  const [username, setUsername] = useState('');
45018
45025
  const onSignInRef = useRef();
@@ -45070,13 +45077,15 @@ const AsgardeoProvider = (props) => {
45070
45077
  isAuthLoading,
45071
45078
  isAuthenticated,
45072
45079
  isBrandingLoading,
45073
- isGlobalLoading: isBrandingLoading || isTextLoading || isAuthLoading,
45080
+ isComponentLoading,
45081
+ isGlobalLoading: isAuthLoading || isBrandingLoading || isComponentLoading || isTextLoading,
45074
45082
  isTextLoading,
45075
45083
  onSignOutRef,
45076
45084
  setAuthResponse,
45077
45085
  setAuthentication,
45078
45086
  setIsAuthLoading,
45079
45087
  setIsBrandingLoading,
45088
+ setIsComponentLoading,
45080
45089
  setIsTextLoading,
45081
45090
  setOnSignIn,
45082
45091
  setOnSignOut,
@@ -45090,9 +45099,11 @@ const AsgardeoProvider = (props) => {
45090
45099
  isAuthLoading,
45091
45100
  isAuthenticated,
45092
45101
  isBrandingLoading,
45102
+ isComponentLoading,
45093
45103
  isTextLoading,
45094
45104
  setAuthResponse,
45095
45105
  setAuthentication,
45106
+ setIsComponentLoading,
45096
45107
  setOnSignIn,
45097
45108
  setOnSignOut,
45098
45109
  setUsername,