@asgardeo/react 0.9.0 → 0.9.2

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/index.js CHANGED
@@ -65,7 +65,8 @@ import {
65
65
  getRedirectBasedSignUpUrl,
66
66
  Platform,
67
67
  isEmpty,
68
- executeEmbeddedSignUpFlowV2
68
+ executeEmbeddedSignUpFlowV2,
69
+ EmbeddedSignInFlowStatusV2
69
70
  } from "@asgardeo/browser";
70
71
 
71
72
  // src/__temp__/api.ts
@@ -118,6 +119,9 @@ var _AuthAPI = class _AuthAPI {
118
119
  async getConfigData() {
119
120
  return this._client.getConfigData();
120
121
  }
122
+ async getStorageManager() {
123
+ return this._client.getStorageManager();
124
+ }
121
125
  /**
122
126
  * Method to get the configuration data.
123
127
  *
@@ -266,6 +270,15 @@ var _AuthAPI = class _AuthAPI {
266
270
  async getHttpClient() {
267
271
  return this._client.getHttpClient();
268
272
  }
273
+ /**
274
+ * This method decodes a JWT token payload and returns it.
275
+ *
276
+ * @param token - The token to decode.
277
+ * @returns The decoded token payload.
278
+ */
279
+ async decodeJwtToken(token) {
280
+ return this._client.decodeJwtToken(token);
281
+ }
269
282
  /**
270
283
  * This method decodes the payload of the id token and returns it.
271
284
  *
@@ -752,12 +765,26 @@ var AsgardeoReactClient = class extends AsgardeoBrowserClient {
752
765
  const authId = authIdFromUrl || authIdFromStorage;
753
766
  const baseUrlFromStorage = sessionStorage.getItem("asgardeo_base_url");
754
767
  const baseUrl = config?.baseUrl || baseUrlFromStorage;
755
- return executeEmbeddedSignInFlowV2({
768
+ const response = await executeEmbeddedSignInFlowV2({
756
769
  payload: arg1,
757
770
  url: arg2?.url,
758
771
  baseUrl,
759
772
  authId
760
773
  });
774
+ if (isV2Platform && response && typeof response === "object" && response["flowStatus"] === EmbeddedSignInFlowStatusV2.Complete && response["assertion"]) {
775
+ const decodedAssertion = await this.decodeJwtToken(response["assertion"]);
776
+ const createdAt = decodedAssertion.iat ? decodedAssertion.iat * 1e3 : Date.now();
777
+ const expiresIn = decodedAssertion.exp && decodedAssertion.iat ? decodedAssertion.exp - decodedAssertion.iat : 3600;
778
+ await this.setSession({
779
+ access_token: response["assertion"],
780
+ id_token: response["assertion"],
781
+ token_type: "Bearer",
782
+ expires_in: expiresIn,
783
+ created_at: createdAt,
784
+ scope: decodedAssertion.scope
785
+ });
786
+ }
787
+ return response;
761
788
  }
762
789
  if (typeof arg1 === "object" && "flowId" in arg1 && typeof arg2 === "object" && "url" in arg2) {
763
790
  return executeEmbeddedSignInFlow({
@@ -789,8 +816,15 @@ var AsgardeoReactClient = class extends AsgardeoBrowserClient {
789
816
  const firstArg = args[0];
790
817
  const baseUrl = config?.baseUrl;
791
818
  if (config.platform === Platform.AsgardeoV2) {
819
+ const authIdFromUrl = new URL(window.location.href).searchParams.get("authId");
820
+ const authIdFromStorage = sessionStorage.getItem("asgardeo_auth_id");
821
+ const authId = authIdFromUrl || authIdFromStorage;
822
+ if (authIdFromUrl && !authIdFromStorage) {
823
+ sessionStorage.setItem("asgardeo_auth_id", authIdFromUrl);
824
+ }
792
825
  return executeEmbeddedSignUpFlowV2({
793
826
  baseUrl,
827
+ authId,
794
828
  payload: typeof firstArg === "object" && "flowType" in firstArg ? { ...firstArg, verbose: true } : firstArg
795
829
  });
796
830
  }
@@ -814,6 +848,12 @@ var AsgardeoReactClient = class extends AsgardeoBrowserClient {
814
848
  clearSession(sessionId) {
815
849
  this.asgardeo.clearSession(sessionId);
816
850
  }
851
+ async setSession(sessionData, sessionId) {
852
+ return await (await this.asgardeo.getStorageManager()).setSessionData(sessionData, sessionId);
853
+ }
854
+ decodeJwtToken(token) {
855
+ return this.asgardeo.decodeJwtToken(token);
856
+ }
817
857
  };
818
858
  var AsgardeoReactClient_default = AsgardeoReactClient;
819
859
 
@@ -7526,7 +7566,6 @@ var BaseSignInContent2 = ({
7526
7566
  setIsSubmitting(true);
7527
7567
  setApiError(null);
7528
7568
  clearMessages();
7529
- console.log("Submitting component:", component, "with data:", data);
7530
7569
  try {
7531
7570
  const filteredInputs = {};
7532
7571
  if (data) {
@@ -7685,7 +7724,7 @@ import { useState as useState16, useEffect as useEffect13, useRef as useRef4 } f
7685
7724
  import {
7686
7725
  AsgardeoRuntimeError as AsgardeoRuntimeError9,
7687
7726
  EmbeddedFlowType,
7688
- EmbeddedSignInFlowStatusV2,
7727
+ EmbeddedSignInFlowStatusV2 as EmbeddedSignInFlowStatusV22,
7689
7728
  EmbeddedSignInFlowTypeV2
7690
7729
  } from "@asgardeo/browser";
7691
7730
 
@@ -8037,7 +8076,7 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
8037
8076
  const { flowId, components: components2, ...rest } = normalizeFlowResponse(response, t, {
8038
8077
  resolveTranslations: !children
8039
8078
  });
8040
- if (response.flowStatus === EmbeddedSignInFlowStatusV2.Error) {
8079
+ if (response.flowStatus === EmbeddedSignInFlowStatusV22.Error) {
8041
8080
  clearFlowState();
8042
8081
  const failureReason = response?.failureReason;
8043
8082
  const errorMessage = failureReason || "Authentication flow failed. Please try again.";
@@ -8046,7 +8085,7 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
8046
8085
  cleanupFlowUrlParams();
8047
8086
  throw err;
8048
8087
  }
8049
- if (response.flowStatus === EmbeddedSignInFlowStatusV2.Complete) {
8088
+ if (response.flowStatus === EmbeddedSignInFlowStatusV22.Complete) {
8050
8089
  const redirectUrl = response?.redirectUrl || response?.redirect_uri;
8051
8090
  const finalRedirectUrl = redirectUrl || afterSignInUrl;
8052
8091
  setIsSubmitting(false);
@@ -10030,6 +10069,11 @@ var SignUp2 = ({
10030
10069
  const handleOnSubmit = async (payload) => await signUp(payload);
10031
10070
  const handleComplete = (response) => {
10032
10071
  onComplete?.(response);
10072
+ const oauthRedirectUrl = response?.redirectUrl;
10073
+ if (shouldRedirectAfterSignUp && oauthRedirectUrl) {
10074
+ window.location.href = oauthRedirectUrl;
10075
+ return;
10076
+ }
10033
10077
  if (shouldRedirectAfterSignUp && response?.type !== EmbeddedFlowResponseType4.Redirection && afterSignUpUrl) {
10034
10078
  window.location.href = afterSignUpUrl;
10035
10079
  }
@@ -15401,7 +15445,7 @@ import {
15401
15445
  EmbeddedFlowActionVariantV2,
15402
15446
  EmbeddedFlowTextVariantV2,
15403
15447
  EmbeddedFlowEventTypeV2,
15404
- EmbeddedSignInFlowStatusV2 as EmbeddedSignInFlowStatusV22,
15448
+ EmbeddedSignInFlowStatusV2 as EmbeddedSignInFlowStatusV23,
15405
15449
  EmbeddedSignInFlowTypeV2 as EmbeddedSignInFlowTypeV22
15406
15450
  } from "@asgardeo/browser";
15407
15451
  export {
@@ -15449,7 +15493,7 @@ export {
15449
15493
  EmbeddedFlowComponentTypeV2 as EmbeddedFlowComponentType,
15450
15494
  EmbeddedFlowEventTypeV2 as EmbeddedFlowEventType,
15451
15495
  EmbeddedFlowTextVariantV2 as EmbeddedFlowTextVariant,
15452
- EmbeddedSignInFlowStatusV22 as EmbeddedSignInFlowStatus,
15496
+ EmbeddedSignInFlowStatusV23 as EmbeddedSignInFlowStatus,
15453
15497
  EmbeddedSignInFlowTypeV22 as EmbeddedSignInFlowType,
15454
15498
  Eye_default as Eye,
15455
15499
  EyeOff_default as EyeOff,