@asgardeo/react 0.6.6 → 0.6.8
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/cjs/index.js +148 -17
- package/dist/cjs/index.js.map +2 -2
- package/dist/index.js +156 -23
- package/dist/index.js.map +3 -3
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -856,12 +856,21 @@ var AsgardeoReactClient = class extends import_browser6.AsgardeoBrowserClient {
|
|
|
856
856
|
const arg1 = args[0];
|
|
857
857
|
const arg2 = args[1];
|
|
858
858
|
const config = await this.asgardeo.getConfigData();
|
|
859
|
-
|
|
860
|
-
|
|
859
|
+
const platformFromStorage = sessionStorage.getItem("asgardeo_platform");
|
|
860
|
+
const isV2Platform = config && config.platform === import_browser6.Platform.AsgardeoV2 || platformFromStorage === "AsgardeoV2";
|
|
861
|
+
if (isV2Platform && typeof arg1 === "object" && arg1 !== null && arg1.callOnlyOnRedirect === true) {
|
|
862
|
+
return void 0;
|
|
863
|
+
}
|
|
864
|
+
if (isV2Platform && typeof arg1 === "object" && arg1 !== null && !(0, import_browser6.isEmpty)(arg1) && ("flowId" in arg1 || "applicationId" in arg1)) {
|
|
865
|
+
const sessionDataKeyFromUrl = new URL(window.location.href).searchParams.get("sessionDataKey");
|
|
866
|
+
const sessionDataKeyFromStorage = sessionStorage.getItem("asgardeo_session_data_key");
|
|
867
|
+
const sessionDataKey = sessionDataKeyFromUrl || sessionDataKeyFromStorage;
|
|
868
|
+
const baseUrlFromStorage = sessionStorage.getItem("asgardeo_base_url");
|
|
869
|
+
const baseUrl = config?.baseUrl || baseUrlFromStorage;
|
|
861
870
|
return (0, import_browser6.executeEmbeddedSignInFlowV2)({
|
|
862
871
|
payload: arg1,
|
|
863
872
|
url: arg2?.url,
|
|
864
|
-
baseUrl
|
|
873
|
+
baseUrl,
|
|
865
874
|
sessionDataKey
|
|
866
875
|
});
|
|
867
876
|
}
|
|
@@ -1609,7 +1618,14 @@ var AsgardeoProvider = ({
|
|
|
1609
1618
|
(0, import_react15.useEffect)(() => {
|
|
1610
1619
|
(async () => {
|
|
1611
1620
|
await asgardeo.initialize(config);
|
|
1612
|
-
|
|
1621
|
+
const initializedConfig = await asgardeo.getConfiguration();
|
|
1622
|
+
setConfig(initializedConfig);
|
|
1623
|
+
if (initializedConfig?.platform) {
|
|
1624
|
+
sessionStorage.setItem("asgardeo_platform", initializedConfig.platform);
|
|
1625
|
+
}
|
|
1626
|
+
if (initializedConfig?.baseUrl) {
|
|
1627
|
+
sessionStorage.setItem("asgardeo_base_url", initializedConfig.baseUrl);
|
|
1628
|
+
}
|
|
1613
1629
|
})();
|
|
1614
1630
|
}, []);
|
|
1615
1631
|
(0, import_react15.useEffect)(() => {
|
|
@@ -1625,7 +1641,8 @@ var AsgardeoProvider = ({
|
|
|
1625
1641
|
}
|
|
1626
1642
|
const currentUrl = new URL(window.location.href);
|
|
1627
1643
|
const hasAuthParamsResult = hasAuthParams(currentUrl, afterSignInUrl);
|
|
1628
|
-
|
|
1644
|
+
const isV2Platform = config.platform === import_browser12.Platform.AsgardeoV2;
|
|
1645
|
+
if (hasAuthParamsResult && !isV2Platform) {
|
|
1629
1646
|
try {
|
|
1630
1647
|
await signIn(
|
|
1631
1648
|
{ callOnlyOnRedirect: true }
|
|
@@ -1780,19 +1797,28 @@ var AsgardeoProvider = ({
|
|
|
1780
1797
|
fetchBranding
|
|
1781
1798
|
]);
|
|
1782
1799
|
const signIn = async (...args) => {
|
|
1800
|
+
const arg1 = args[0];
|
|
1801
|
+
const isV2FlowRequest = config.platform === import_browser12.Platform.AsgardeoV2 && typeof arg1 === "object" && arg1 !== null && ("flowId" in arg1 || "applicationId" in arg1);
|
|
1783
1802
|
try {
|
|
1784
|
-
|
|
1785
|
-
|
|
1803
|
+
if (!isV2FlowRequest) {
|
|
1804
|
+
setIsUpdatingSession(true);
|
|
1805
|
+
setIsLoadingSync(true);
|
|
1806
|
+
}
|
|
1786
1807
|
const response = await asgardeo.signIn(...args);
|
|
1808
|
+
if (isV2FlowRequest || response && typeof response === "object" && "flowStatus" in response) {
|
|
1809
|
+
return response;
|
|
1810
|
+
}
|
|
1787
1811
|
if (await asgardeo.isSignedIn()) {
|
|
1788
1812
|
await updateSession();
|
|
1789
1813
|
}
|
|
1790
1814
|
return response;
|
|
1791
1815
|
} catch (error) {
|
|
1792
|
-
throw new Error(`Error while signing in: ${error}`);
|
|
1816
|
+
throw new Error(`Error while signing in: ${error instanceof Error ? error.message : String(error)}`);
|
|
1793
1817
|
} finally {
|
|
1794
|
-
|
|
1795
|
-
|
|
1818
|
+
if (!isV2FlowRequest) {
|
|
1819
|
+
setIsUpdatingSession(false);
|
|
1820
|
+
setIsLoadingSync(asgardeo.isLoading());
|
|
1821
|
+
}
|
|
1796
1822
|
}
|
|
1797
1823
|
};
|
|
1798
1824
|
const signInSilently = async (options) => {
|
|
@@ -7616,16 +7642,62 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
|
|
|
7616
7642
|
const [flowError, setFlowError] = (0, import_react59.useState)(null);
|
|
7617
7643
|
const [isSubmitting, setIsSubmitting] = (0, import_react59.useState)(false);
|
|
7618
7644
|
const initializationAttemptedRef = (0, import_react59.useRef)(false);
|
|
7645
|
+
const oauthCodeProcessedRef = (0, import_react59.useRef)(false);
|
|
7646
|
+
const handleRedirection = (response) => {
|
|
7647
|
+
if (response.type === import_browser51.EmbeddedSignInFlowTypeV2.Redirection) {
|
|
7648
|
+
const redirectURL = response.data?.redirectURL || response?.redirectURL;
|
|
7649
|
+
if (redirectURL) {
|
|
7650
|
+
if (response.flowId) {
|
|
7651
|
+
sessionStorage.setItem("asgardeo_flow_id", response.flowId);
|
|
7652
|
+
}
|
|
7653
|
+
const urlParams = new URL(window.location.href).searchParams;
|
|
7654
|
+
const sessionDataKeyFromUrl = urlParams.get("sessionDataKey");
|
|
7655
|
+
if (sessionDataKeyFromUrl) {
|
|
7656
|
+
sessionStorage.setItem("asgardeo_session_data_key", sessionDataKeyFromUrl);
|
|
7657
|
+
}
|
|
7658
|
+
window.location.href = redirectURL;
|
|
7659
|
+
return true;
|
|
7660
|
+
}
|
|
7661
|
+
}
|
|
7662
|
+
return false;
|
|
7663
|
+
};
|
|
7619
7664
|
(0, import_react59.useEffect)(() => {
|
|
7620
|
-
|
|
7665
|
+
const storedFlowId = sessionStorage.getItem("asgardeo_flow_id");
|
|
7666
|
+
const urlParams = new URL(window.location.href).searchParams;
|
|
7667
|
+
const code = urlParams.get("code");
|
|
7668
|
+
const state = urlParams.get("state");
|
|
7669
|
+
const sessionDataKeyFromUrl = urlParams.get("sessionDataKey");
|
|
7670
|
+
if (sessionDataKeyFromUrl) {
|
|
7671
|
+
sessionStorage.setItem("asgardeo_session_data_key", sessionDataKeyFromUrl);
|
|
7672
|
+
}
|
|
7673
|
+
if (code) {
|
|
7674
|
+
const flowIdFromUrl = urlParams.get("flowId");
|
|
7675
|
+
const flowIdFromState = state || flowIdFromUrl || storedFlowId;
|
|
7676
|
+
if (flowIdFromState) {
|
|
7677
|
+
setCurrentFlowId(flowIdFromState);
|
|
7678
|
+
setIsFlowInitialized(true);
|
|
7679
|
+
sessionStorage.setItem("asgardeo_flow_id", flowIdFromState);
|
|
7680
|
+
initializationAttemptedRef.current = true;
|
|
7681
|
+
}
|
|
7682
|
+
return;
|
|
7683
|
+
}
|
|
7684
|
+
if (isInitialized && !isLoading && !isFlowInitialized && !initializationAttemptedRef.current && !currentFlowId) {
|
|
7621
7685
|
initializationAttemptedRef.current = true;
|
|
7622
7686
|
initializeFlow();
|
|
7623
7687
|
}
|
|
7624
|
-
}, [isInitialized, isLoading, isFlowInitialized]);
|
|
7688
|
+
}, [isInitialized, isLoading, isFlowInitialized, currentFlowId]);
|
|
7625
7689
|
const initializeFlow = async () => {
|
|
7626
7690
|
const urlParams = new URL(window.location.href).searchParams;
|
|
7691
|
+
const code = urlParams.get("code");
|
|
7692
|
+
if (code) {
|
|
7693
|
+
return;
|
|
7694
|
+
}
|
|
7627
7695
|
const flowIdFromUrl = urlParams.get("flowId");
|
|
7628
7696
|
const applicationIdFromUrl = urlParams.get("applicationId");
|
|
7697
|
+
const sessionDataKeyFromUrl = urlParams.get("sessionDataKey");
|
|
7698
|
+
if (sessionDataKeyFromUrl) {
|
|
7699
|
+
sessionStorage.setItem("asgardeo_session_data_key", sessionDataKeyFromUrl);
|
|
7700
|
+
}
|
|
7629
7701
|
const effectiveApplicationId = applicationId || applicationIdFromUrl;
|
|
7630
7702
|
if (!flowIdFromUrl && !effectiveApplicationId) {
|
|
7631
7703
|
const error = new import_browser51.AsgardeoRuntimeError(
|
|
@@ -7650,6 +7722,9 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
|
|
|
7650
7722
|
flowType: import_browser51.EmbeddedFlowType.Authentication
|
|
7651
7723
|
});
|
|
7652
7724
|
}
|
|
7725
|
+
if (handleRedirection(response)) {
|
|
7726
|
+
return;
|
|
7727
|
+
}
|
|
7653
7728
|
const { flowId, components: components2 } = normalizeFlowResponse(response, t);
|
|
7654
7729
|
if (flowId && components2) {
|
|
7655
7730
|
setCurrentFlowId(flowId);
|
|
@@ -7669,29 +7744,53 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
|
|
|
7669
7744
|
}
|
|
7670
7745
|
};
|
|
7671
7746
|
const handleSubmit = async (payload) => {
|
|
7672
|
-
|
|
7747
|
+
const effectiveFlowId = payload.flowId || currentFlowId;
|
|
7748
|
+
if (!effectiveFlowId) {
|
|
7749
|
+
console.error("[SignIn] handleSubmit - ERROR: No flowId available", {
|
|
7750
|
+
payloadFlowId: payload.flowId,
|
|
7751
|
+
currentFlowId
|
|
7752
|
+
});
|
|
7673
7753
|
throw new Error("No active flow ID");
|
|
7674
7754
|
}
|
|
7675
7755
|
try {
|
|
7676
7756
|
setIsSubmitting(true);
|
|
7677
7757
|
setFlowError(null);
|
|
7678
7758
|
const response = await signIn({
|
|
7679
|
-
flowId:
|
|
7759
|
+
flowId: effectiveFlowId,
|
|
7680
7760
|
...payload
|
|
7681
7761
|
});
|
|
7762
|
+
if (handleRedirection(response)) {
|
|
7763
|
+
return;
|
|
7764
|
+
}
|
|
7682
7765
|
const { flowId, components: components2 } = normalizeFlowResponse(response, t);
|
|
7683
7766
|
if (response.flowStatus === import_browser51.EmbeddedSignInFlowStatusV2.Complete) {
|
|
7767
|
+
const redirectUrl = response.redirectUrl || response.redirect_uri;
|
|
7768
|
+
sessionStorage.removeItem("asgardeo_flow_id");
|
|
7769
|
+
if (redirectUrl) {
|
|
7770
|
+
sessionStorage.removeItem("asgardeo_session_data_key");
|
|
7771
|
+
}
|
|
7772
|
+
const url = new URL(window.location.href);
|
|
7773
|
+
url.searchParams.delete("code");
|
|
7774
|
+
url.searchParams.delete("state");
|
|
7775
|
+
url.searchParams.delete("nonce");
|
|
7776
|
+
window.history.replaceState({}, "", url.toString());
|
|
7777
|
+
const finalRedirectUrl = redirectUrl || afterSignInUrl;
|
|
7684
7778
|
onSuccess && onSuccess({
|
|
7685
|
-
redirectUrl:
|
|
7779
|
+
redirectUrl: finalRedirectUrl,
|
|
7686
7780
|
...response.data
|
|
7687
7781
|
});
|
|
7688
|
-
|
|
7782
|
+
if (finalRedirectUrl) {
|
|
7783
|
+
window.location.href = finalRedirectUrl;
|
|
7784
|
+
}
|
|
7689
7785
|
return;
|
|
7690
7786
|
}
|
|
7691
7787
|
if (flowId && components2) {
|
|
7692
7788
|
setCurrentFlowId(flowId);
|
|
7693
7789
|
setComponents(components2);
|
|
7694
7790
|
}
|
|
7791
|
+
if (!currentFlowId && effectiveFlowId) {
|
|
7792
|
+
setCurrentFlowId(effectiveFlowId);
|
|
7793
|
+
}
|
|
7695
7794
|
} catch (error) {
|
|
7696
7795
|
const err = error;
|
|
7697
7796
|
setFlowError(err);
|
|
@@ -7711,6 +7810,36 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
|
|
|
7711
7810
|
setFlowError(error);
|
|
7712
7811
|
onError?.(error);
|
|
7713
7812
|
};
|
|
7813
|
+
(0, import_react59.useEffect)(() => {
|
|
7814
|
+
const urlParams = new URL(window.location.href).searchParams;
|
|
7815
|
+
const code = urlParams.get("code");
|
|
7816
|
+
const nonce = urlParams.get("nonce");
|
|
7817
|
+
const state = urlParams.get("state");
|
|
7818
|
+
const flowIdFromUrl = urlParams.get("flowId");
|
|
7819
|
+
const storedFlowId = sessionStorage.getItem("asgardeo_flow_id");
|
|
7820
|
+
if (!code || oauthCodeProcessedRef.current || isSubmitting) {
|
|
7821
|
+
return;
|
|
7822
|
+
}
|
|
7823
|
+
const flowIdToUse = currentFlowId || state || flowIdFromUrl || storedFlowId;
|
|
7824
|
+
if (!flowIdToUse || !signIn) {
|
|
7825
|
+
return;
|
|
7826
|
+
}
|
|
7827
|
+
oauthCodeProcessedRef.current = true;
|
|
7828
|
+
if (!currentFlowId) {
|
|
7829
|
+
setCurrentFlowId(flowIdToUse);
|
|
7830
|
+
setIsFlowInitialized(true);
|
|
7831
|
+
}
|
|
7832
|
+
const submitPayload = {
|
|
7833
|
+
flowId: flowIdToUse,
|
|
7834
|
+
inputs: {
|
|
7835
|
+
code,
|
|
7836
|
+
...nonce && { nonce }
|
|
7837
|
+
}
|
|
7838
|
+
};
|
|
7839
|
+
handleSubmit(submitPayload).catch(() => {
|
|
7840
|
+
oauthCodeProcessedRef.current = false;
|
|
7841
|
+
});
|
|
7842
|
+
}, [isFlowInitialized, currentFlowId, isInitialized, isLoading, isSubmitting, signIn]);
|
|
7714
7843
|
if (children) {
|
|
7715
7844
|
const renderProps = {
|
|
7716
7845
|
initialize: initializeFlow,
|
|
@@ -8509,6 +8638,7 @@ var BaseSignUpContent = ({
|
|
|
8509
8638
|
const { theme, colorScheme } = useTheme_default();
|
|
8510
8639
|
const { t } = useTranslation_default();
|
|
8511
8640
|
const { subtitle: flowSubtitle, title: flowTitle, messages: flowMessages, addMessage, clearMessages } = useFlow_default();
|
|
8641
|
+
const { platform } = useAsgardeo_default();
|
|
8512
8642
|
const styles = BaseSignUp_styles_default(theme, colorScheme);
|
|
8513
8643
|
const handleError = (0, import_react61.useCallback)(
|
|
8514
8644
|
(error) => {
|
|
@@ -8634,11 +8764,12 @@ var BaseSignUpContent = ({
|
|
|
8634
8764
|
}
|
|
8635
8765
|
});
|
|
8636
8766
|
}
|
|
8767
|
+
const actionId = platform === import_browser61.Platform.AsgardeoV2 ? component.config?.actionId : component.id;
|
|
8637
8768
|
const payload = {
|
|
8638
8769
|
...currentFlow.flowId && { flowId: currentFlow.flowId },
|
|
8639
8770
|
flowType: currentFlow.flowType || "REGISTRATION",
|
|
8640
8771
|
inputs: filteredInputs,
|
|
8641
|
-
actionId
|
|
8772
|
+
...actionId && { actionId }
|
|
8642
8773
|
};
|
|
8643
8774
|
const rawResponse = await onSubmit(payload);
|
|
8644
8775
|
const response = normalizeFlowResponse2(rawResponse);
|