@asgardeo/react 0.6.5 → 0.6.7

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.
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import { FC } from 'react';
19
+ import { BaseSignUpOptionProps } from '../presentation/SignUp/SignUpOptionFactory';
20
+ /**
21
+ * Select input component for sign-up forms.
22
+ */
23
+ declare const SelectInput: FC<BaseSignUpOptionProps>;
24
+ export default SelectInput;
package/dist/index.js CHANGED
@@ -742,12 +742,21 @@ var AsgardeoReactClient = class extends AsgardeoBrowserClient {
742
742
  const arg1 = args[0];
743
743
  const arg2 = args[1];
744
744
  const config = await this.asgardeo.getConfigData();
745
- if (config.platform === Platform.AsgardeoV2 && typeof arg1 === "object" && !isEmpty(arg1) && ("flowId" in arg1 || "applicationId" in arg1)) {
746
- const sessionDataKey = new URL(window.location.href).searchParams.get("sessionDataKey");
745
+ const platformFromStorage = sessionStorage.getItem("asgardeo_platform");
746
+ const isV2Platform = config && config.platform === Platform.AsgardeoV2 || platformFromStorage === "AsgardeoV2";
747
+ if (isV2Platform && typeof arg1 === "object" && arg1 !== null && arg1.callOnlyOnRedirect === true) {
748
+ return void 0;
749
+ }
750
+ if (isV2Platform && typeof arg1 === "object" && arg1 !== null && !isEmpty(arg1) && ("flowId" in arg1 || "applicationId" in arg1)) {
751
+ const sessionDataKeyFromUrl = new URL(window.location.href).searchParams.get("sessionDataKey");
752
+ const sessionDataKeyFromStorage = sessionStorage.getItem("asgardeo_session_data_key");
753
+ const sessionDataKey = sessionDataKeyFromUrl || sessionDataKeyFromStorage;
754
+ const baseUrlFromStorage = sessionStorage.getItem("asgardeo_base_url");
755
+ const baseUrl = config?.baseUrl || baseUrlFromStorage;
747
756
  return executeEmbeddedSignInFlowV2({
748
757
  payload: arg1,
749
758
  url: arg2?.url,
750
- baseUrl: config?.baseUrl,
759
+ baseUrl,
751
760
  sessionDataKey
752
761
  });
753
762
  }
@@ -1503,7 +1512,14 @@ var AsgardeoProvider = ({
1503
1512
  useEffect5(() => {
1504
1513
  (async () => {
1505
1514
  await asgardeo.initialize(config);
1506
- setConfig(await asgardeo.getConfiguration());
1515
+ const initializedConfig = await asgardeo.getConfiguration();
1516
+ setConfig(initializedConfig);
1517
+ if (initializedConfig?.platform) {
1518
+ sessionStorage.setItem("asgardeo_platform", initializedConfig.platform);
1519
+ }
1520
+ if (initializedConfig?.baseUrl) {
1521
+ sessionStorage.setItem("asgardeo_base_url", initializedConfig.baseUrl);
1522
+ }
1507
1523
  })();
1508
1524
  }, []);
1509
1525
  useEffect5(() => {
@@ -1519,7 +1535,8 @@ var AsgardeoProvider = ({
1519
1535
  }
1520
1536
  const currentUrl = new URL(window.location.href);
1521
1537
  const hasAuthParamsResult = hasAuthParams(currentUrl, afterSignInUrl);
1522
- if (hasAuthParamsResult) {
1538
+ const isV2Platform = config.platform === Platform2.AsgardeoV2;
1539
+ if (hasAuthParamsResult && !isV2Platform) {
1523
1540
  try {
1524
1541
  await signIn(
1525
1542
  { callOnlyOnRedirect: true }
@@ -1674,19 +1691,28 @@ var AsgardeoProvider = ({
1674
1691
  fetchBranding
1675
1692
  ]);
1676
1693
  const signIn = async (...args) => {
1694
+ const arg1 = args[0];
1695
+ const isV2FlowRequest = config.platform === Platform2.AsgardeoV2 && typeof arg1 === "object" && arg1 !== null && ("flowId" in arg1 || "applicationId" in arg1);
1677
1696
  try {
1678
- setIsUpdatingSession(true);
1679
- setIsLoadingSync(true);
1697
+ if (!isV2FlowRequest) {
1698
+ setIsUpdatingSession(true);
1699
+ setIsLoadingSync(true);
1700
+ }
1680
1701
  const response = await asgardeo.signIn(...args);
1702
+ if (isV2FlowRequest || response && typeof response === "object" && "flowStatus" in response) {
1703
+ return response;
1704
+ }
1681
1705
  if (await asgardeo.isSignedIn()) {
1682
1706
  await updateSession();
1683
1707
  }
1684
1708
  return response;
1685
1709
  } catch (error) {
1686
- throw new Error(`Error while signing in: ${error}`);
1710
+ throw new Error(`Error while signing in: ${error instanceof Error ? error.message : String(error)}`);
1687
1711
  } finally {
1688
- setIsUpdatingSession(false);
1689
- setIsLoadingSync(asgardeo.isLoading());
1712
+ if (!isV2FlowRequest) {
1713
+ setIsUpdatingSession(false);
1714
+ setIsLoadingSync(asgardeo.isLoading());
1715
+ }
1690
1716
  }
1691
1717
  };
1692
1718
  const signInSilently = async (options) => {
@@ -7032,6 +7058,25 @@ var convertSimpleInputToComponent = (input, t) => {
7032
7058
  if (input.name.toLowerCase().includes("password") && input.type.toLowerCase() === "string") {
7033
7059
  fieldType = "password";
7034
7060
  }
7061
+ if (input.type.toLowerCase() === "dropdown") {
7062
+ const label2 = getInputLabel(input.name, fieldType, t);
7063
+ const placeholder2 = getInputPlaceholder(input.name, fieldType, t);
7064
+ return {
7065
+ id: generateId("select"),
7066
+ type: EmbeddedFlowComponentType2.Select,
7067
+ variant: "SELECT",
7068
+ config: {
7069
+ type: fieldType,
7070
+ label: label2,
7071
+ placeholder: placeholder2,
7072
+ required: input.required,
7073
+ identifier: input.name,
7074
+ hint: "",
7075
+ options: input.options || []
7076
+ },
7077
+ components: []
7078
+ };
7079
+ }
7035
7080
  const variant = getInputVariant(fieldType, input.name);
7036
7081
  const label = getInputLabel(input.name, fieldType, t);
7037
7082
  const placeholder = getInputPlaceholder(input.name, fieldType, t);
@@ -7393,7 +7438,8 @@ import { useState as useState16, useEffect as useEffect13, useRef as useRef4 } f
7393
7438
  import {
7394
7439
  AsgardeoRuntimeError as AsgardeoRuntimeError8,
7395
7440
  EmbeddedFlowType,
7396
- EmbeddedSignInFlowStatusV2
7441
+ EmbeddedSignInFlowStatusV2,
7442
+ EmbeddedSignInFlowTypeV2
7397
7443
  } from "@asgardeo/browser";
7398
7444
 
7399
7445
  // src/components/presentation/SignIn/component-driven/transformer.ts
@@ -7522,16 +7568,62 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7522
7568
  const [flowError, setFlowError] = useState16(null);
7523
7569
  const [isSubmitting, setIsSubmitting] = useState16(false);
7524
7570
  const initializationAttemptedRef = useRef4(false);
7571
+ const oauthCodeProcessedRef = useRef4(false);
7572
+ const handleRedirection = (response) => {
7573
+ if (response.type === EmbeddedSignInFlowTypeV2.Redirection) {
7574
+ const redirectURL = response.data?.redirectURL || response?.redirectURL;
7575
+ if (redirectURL) {
7576
+ if (response.flowId) {
7577
+ sessionStorage.setItem("asgardeo_flow_id", response.flowId);
7578
+ }
7579
+ const urlParams = new URL(window.location.href).searchParams;
7580
+ const sessionDataKeyFromUrl = urlParams.get("sessionDataKey");
7581
+ if (sessionDataKeyFromUrl) {
7582
+ sessionStorage.setItem("asgardeo_session_data_key", sessionDataKeyFromUrl);
7583
+ }
7584
+ window.location.href = redirectURL;
7585
+ return true;
7586
+ }
7587
+ }
7588
+ return false;
7589
+ };
7525
7590
  useEffect13(() => {
7526
- if (isInitialized && !isLoading && !isFlowInitialized && !initializationAttemptedRef.current) {
7591
+ const storedFlowId = sessionStorage.getItem("asgardeo_flow_id");
7592
+ const urlParams = new URL(window.location.href).searchParams;
7593
+ const code = urlParams.get("code");
7594
+ const state = urlParams.get("state");
7595
+ const sessionDataKeyFromUrl = urlParams.get("sessionDataKey");
7596
+ if (sessionDataKeyFromUrl) {
7597
+ sessionStorage.setItem("asgardeo_session_data_key", sessionDataKeyFromUrl);
7598
+ }
7599
+ if (code) {
7600
+ const flowIdFromUrl = urlParams.get("flowId");
7601
+ const flowIdFromState = state || flowIdFromUrl || storedFlowId;
7602
+ if (flowIdFromState) {
7603
+ setCurrentFlowId(flowIdFromState);
7604
+ setIsFlowInitialized(true);
7605
+ sessionStorage.setItem("asgardeo_flow_id", flowIdFromState);
7606
+ initializationAttemptedRef.current = true;
7607
+ }
7608
+ return;
7609
+ }
7610
+ if (isInitialized && !isLoading && !isFlowInitialized && !initializationAttemptedRef.current && !currentFlowId) {
7527
7611
  initializationAttemptedRef.current = true;
7528
7612
  initializeFlow();
7529
7613
  }
7530
- }, [isInitialized, isLoading, isFlowInitialized]);
7614
+ }, [isInitialized, isLoading, isFlowInitialized, currentFlowId]);
7531
7615
  const initializeFlow = async () => {
7532
7616
  const urlParams = new URL(window.location.href).searchParams;
7617
+ const code = urlParams.get("code");
7618
+ if (code) {
7619
+ return;
7620
+ }
7533
7621
  const flowIdFromUrl = urlParams.get("flowId");
7534
7622
  const applicationIdFromUrl = urlParams.get("applicationId");
7623
+ const sessionDataKeyFromUrl = urlParams.get("sessionDataKey");
7624
+ if (sessionDataKeyFromUrl) {
7625
+ sessionStorage.setItem("asgardeo_session_data_key", sessionDataKeyFromUrl);
7626
+ }
7535
7627
  const effectiveApplicationId = applicationId || applicationIdFromUrl;
7536
7628
  if (!flowIdFromUrl && !effectiveApplicationId) {
7537
7629
  const error = new AsgardeoRuntimeError8(
@@ -7556,6 +7648,9 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7556
7648
  flowType: EmbeddedFlowType.Authentication
7557
7649
  });
7558
7650
  }
7651
+ if (handleRedirection(response)) {
7652
+ return;
7653
+ }
7559
7654
  const { flowId, components: components2 } = normalizeFlowResponse(response, t);
7560
7655
  if (flowId && components2) {
7561
7656
  setCurrentFlowId(flowId);
@@ -7575,29 +7670,53 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7575
7670
  }
7576
7671
  };
7577
7672
  const handleSubmit = async (payload) => {
7578
- if (!currentFlowId) {
7673
+ const effectiveFlowId = payload.flowId || currentFlowId;
7674
+ if (!effectiveFlowId) {
7675
+ console.error("[SignIn] handleSubmit - ERROR: No flowId available", {
7676
+ payloadFlowId: payload.flowId,
7677
+ currentFlowId
7678
+ });
7579
7679
  throw new Error("No active flow ID");
7580
7680
  }
7581
7681
  try {
7582
7682
  setIsSubmitting(true);
7583
7683
  setFlowError(null);
7584
7684
  const response = await signIn({
7585
- flowId: currentFlowId,
7685
+ flowId: effectiveFlowId,
7586
7686
  ...payload
7587
7687
  });
7688
+ if (handleRedirection(response)) {
7689
+ return;
7690
+ }
7588
7691
  const { flowId, components: components2 } = normalizeFlowResponse(response, t);
7589
7692
  if (response.flowStatus === EmbeddedSignInFlowStatusV2.Complete) {
7693
+ const redirectUrl = response.redirectUrl || response.redirect_uri;
7694
+ sessionStorage.removeItem("asgardeo_flow_id");
7695
+ if (redirectUrl) {
7696
+ sessionStorage.removeItem("asgardeo_session_data_key");
7697
+ }
7698
+ const url = new URL(window.location.href);
7699
+ url.searchParams.delete("code");
7700
+ url.searchParams.delete("state");
7701
+ url.searchParams.delete("nonce");
7702
+ window.history.replaceState({}, "", url.toString());
7703
+ const finalRedirectUrl = redirectUrl || afterSignInUrl;
7590
7704
  onSuccess && onSuccess({
7591
- redirectUrl: response.redirectUrl || afterSignInUrl,
7705
+ redirectUrl: finalRedirectUrl,
7592
7706
  ...response.data
7593
7707
  });
7594
- window.location.href = response.redirectUrl || afterSignInUrl;
7708
+ if (finalRedirectUrl) {
7709
+ window.location.href = finalRedirectUrl;
7710
+ }
7595
7711
  return;
7596
7712
  }
7597
7713
  if (flowId && components2) {
7598
7714
  setCurrentFlowId(flowId);
7599
7715
  setComponents(components2);
7600
7716
  }
7717
+ if (!currentFlowId && effectiveFlowId) {
7718
+ setCurrentFlowId(effectiveFlowId);
7719
+ }
7601
7720
  } catch (error) {
7602
7721
  const err = error;
7603
7722
  setFlowError(err);
@@ -7617,6 +7736,36 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7617
7736
  setFlowError(error);
7618
7737
  onError?.(error);
7619
7738
  };
7739
+ useEffect13(() => {
7740
+ const urlParams = new URL(window.location.href).searchParams;
7741
+ const code = urlParams.get("code");
7742
+ const nonce = urlParams.get("nonce");
7743
+ const state = urlParams.get("state");
7744
+ const flowIdFromUrl = urlParams.get("flowId");
7745
+ const storedFlowId = sessionStorage.getItem("asgardeo_flow_id");
7746
+ if (!code || oauthCodeProcessedRef.current || isSubmitting) {
7747
+ return;
7748
+ }
7749
+ const flowIdToUse = currentFlowId || state || flowIdFromUrl || storedFlowId;
7750
+ if (!flowIdToUse || !signIn) {
7751
+ return;
7752
+ }
7753
+ oauthCodeProcessedRef.current = true;
7754
+ if (!currentFlowId) {
7755
+ setCurrentFlowId(flowIdToUse);
7756
+ setIsFlowInitialized(true);
7757
+ }
7758
+ const submitPayload = {
7759
+ flowId: flowIdToUse,
7760
+ inputs: {
7761
+ code,
7762
+ ...nonce && { nonce }
7763
+ }
7764
+ };
7765
+ handleSubmit(submitPayload).catch(() => {
7766
+ oauthCodeProcessedRef.current = false;
7767
+ });
7768
+ }, [isFlowInitialized, currentFlowId, isInitialized, isLoading, isSubmitting, signIn]);
7620
7769
  if (children) {
7621
7770
  const renderProps = {
7622
7771
  initialize: initializeFlow,
@@ -7701,7 +7850,8 @@ import {
7701
7850
  EmbeddedFlowStatus,
7702
7851
  EmbeddedFlowComponentType as EmbeddedFlowComponentType5,
7703
7852
  EmbeddedFlowResponseType,
7704
- withVendorCSSClassPrefix as withVendorCSSClassPrefix21
7853
+ withVendorCSSClassPrefix as withVendorCSSClassPrefix21,
7854
+ Platform as Platform5
7705
7855
  } from "@asgardeo/browser";
7706
7856
  import { cx as cx21 } from "@emotion/css";
7707
7857
  import { useEffect as useEffect14, useState as useState17, useCallback as useCallback11, useRef as useRef5 } from "react";
@@ -8070,6 +8220,40 @@ var TextInput = ({
8070
8220
  };
8071
8221
  var TextInput_default = TextInput;
8072
8222
 
8223
+ // src/components/adapters/SelectInput.tsx
8224
+ import { FieldType as FieldType14 } from "@asgardeo/browser";
8225
+ var SelectInput = ({
8226
+ component,
8227
+ formValues,
8228
+ touchedFields,
8229
+ formErrors,
8230
+ onInputChange,
8231
+ inputClassName
8232
+ }) => {
8233
+ const config = component.config || {};
8234
+ const fieldName = config["identifier"] || config["name"] || component.id;
8235
+ const value = formValues[fieldName] || "";
8236
+ const error = touchedFields[fieldName] ? formErrors[fieldName] : void 0;
8237
+ const rawOptions = config["options"] || [];
8238
+ const options = rawOptions.map((option) => ({
8239
+ label: option,
8240
+ value: option
8241
+ }));
8242
+ return createField({
8243
+ type: FieldType14.Select,
8244
+ name: fieldName,
8245
+ label: config["label"] || "",
8246
+ placeholder: config["placeholder"] || "",
8247
+ required: config["required"] || false,
8248
+ value,
8249
+ error,
8250
+ options,
8251
+ onChange: (newValue) => onInputChange(fieldName, newValue),
8252
+ className: inputClassName
8253
+ });
8254
+ };
8255
+ var SelectInput_default = SelectInput;
8256
+
8073
8257
  // src/components/adapters/Typography.tsx
8074
8258
  import { jsx as jsx65 } from "react/jsx-runtime";
8075
8259
  var TypographyComponent = ({ component }) => {
@@ -8179,6 +8363,8 @@ var createSignUpComponent = ({ component, onSubmit, ...rest }) => {
8179
8363
  }
8180
8364
  case EmbeddedFlowComponentType4.Form:
8181
8365
  return /* @__PURE__ */ jsx66(FormContainer_default, { component, onSubmit, ...rest });
8366
+ case EmbeddedFlowComponentType4.Select:
8367
+ return /* @__PURE__ */ jsx66(SelectInput_default, { component, onSubmit, ...rest });
8182
8368
  case EmbeddedFlowComponentType4.Divider:
8183
8369
  return /* @__PURE__ */ jsx66(DividerComponent_default, { component, onSubmit, ...rest });
8184
8370
  case EmbeddedFlowComponentType4.Image:
@@ -8384,6 +8570,7 @@ var BaseSignUpContent = ({
8384
8570
  const { theme, colorScheme } = useTheme_default();
8385
8571
  const { t } = useTranslation_default();
8386
8572
  const { subtitle: flowSubtitle, title: flowTitle, messages: flowMessages, addMessage, clearMessages } = useFlow_default();
8573
+ const { platform } = useAsgardeo_default();
8387
8574
  const styles = BaseSignUp_styles_default(theme, colorScheme);
8388
8575
  const handleError = useCallback11(
8389
8576
  (error) => {
@@ -8509,11 +8696,12 @@ var BaseSignUpContent = ({
8509
8696
  }
8510
8697
  });
8511
8698
  }
8699
+ const actionId = platform === Platform5.AsgardeoV2 ? component.config?.actionId : component.id;
8512
8700
  const payload = {
8513
8701
  ...currentFlow.flowId && { flowId: currentFlow.flowId },
8514
8702
  flowType: currentFlow.flowType || "REGISTRATION",
8515
8703
  inputs: filteredInputs,
8516
- actionId: component.id
8704
+ ...actionId && { actionId }
8517
8705
  };
8518
8706
  const rawResponse = await onSubmit(payload);
8519
8707
  const response = normalizeFlowResponse2(rawResponse);
@@ -8796,7 +8984,7 @@ var BaseSignUp_default = BaseSignUp;
8796
8984
  import {
8797
8985
  EmbeddedFlowResponseType as EmbeddedFlowResponseType2,
8798
8986
  EmbeddedFlowType as EmbeddedFlowType2,
8799
- Platform as Platform5
8987
+ Platform as Platform6
8800
8988
  } from "@asgardeo/browser";
8801
8989
  import { jsx as jsx68 } from "react/jsx-runtime";
8802
8990
  var SignUp = ({
@@ -8816,7 +9004,7 @@ var SignUp = ({
8816
9004
  const effectiveApplicationId = applicationId || applicationIdFromUrl;
8817
9005
  const initialPayload = payload || {
8818
9006
  flowType: EmbeddedFlowType2.Registration,
8819
- ...platform === Platform5.AsgardeoV2 && effectiveApplicationId && { applicationId: effectiveApplicationId }
9007
+ ...platform === Platform6.AsgardeoV2 && effectiveApplicationId && { applicationId: effectiveApplicationId }
8820
9008
  };
8821
9009
  return await signUp(initialPayload);
8822
9010
  };
@@ -8844,8 +9032,8 @@ var SignUp = ({
8844
9032
  isInitialized,
8845
9033
  children,
8846
9034
  showLogo: true,
8847
- showTitle: platform === Platform5.AsgardeoV2,
8848
- showSubtitle: platform === Platform5.AsgardeoV2,
9035
+ showTitle: platform === Platform6.AsgardeoV2,
9036
+ showSubtitle: platform === Platform6.AsgardeoV2,
8849
9037
  ...rest
8850
9038
  }
8851
9039
  );