diff --git a/packages/elements-react/src/theme/default/components/form/text.tsx b/packages/elements-react/src/theme/default/components/form/text.tsx index 5bbf28be..61bd8c70 100644 --- a/packages/elements-react/src/theme/default/components/form/text.tsx +++ b/packages/elements-react/src/theme/default/components/form/text.tsx @@ -17,7 +17,10 @@ export function DefaultText({ node, attributes }: OryNodeTextProps) { secrets: UiText[] } ).secrets?.map((text: UiText, index) => ( -
+        
           {text ? uiTextToFormattedMessage(text, intl) : ""}
         
))} diff --git a/packages/elements-react/src/theme/default/utils/__tests__/url.spec.ts b/packages/elements-react/src/theme/default/utils/__tests__/url.spec.ts new file mode 100644 index 00000000..521914bd --- /dev/null +++ b/packages/elements-react/src/theme/default/utils/__tests__/url.spec.ts @@ -0,0 +1,61 @@ +import { restartFlowUrl, initFlowUrl } from "../url" + +describe("url utils", () => { + describe("restartFlowUrl", () => { + it("should return request_url if present", () => { + const flow = { request_url: "http://example.com/request" } + const fallback = "http://example.com/fallback" + expect(restartFlowUrl(flow, fallback)).toBe(flow.request_url) + }) + + it("should return fallback with return_to if request_url is not present", () => { + const flow = { return_to: "http://example.com/return" } + const fallback = "http://example.com/fallback" + expect(restartFlowUrl(flow, fallback)).toBe( + "http://example.com/fallback?return_to=http%3A%2F%2Fexample.com%2Freturn", + ) + }) + + it("should return fallback if neither request_url nor return_to are present", () => { + const flow = {} + const fallback = "http://example.com/fallback" + expect(restartFlowUrl(flow, fallback)).toBe(fallback) + }) + }) + + describe("initFlowUrl", () => { + it("should return sdkUrl with flowType and return_to if present in flow", () => { + const sdkUrl = "http://example.com" + const flowType = "login" + const flow = { return_to: "http://example.com/return" } + expect(initFlowUrl(sdkUrl, flowType, flow)).toBe( + "http://example.com/self-service/login/browser?return_to=http%3A%2F%2Fexample.com%2Freturn", + ) + }) + + xit("should return sdkUrl with flowType and return_to if present in window location", () => { + const sdkUrl = "http://example.com" + const flowType = "login" + const flow = {} + + // Not sure how to mock this. + ;(window.location.href = + "http://example.com?return_to=http://example.com/return"), + expect(initFlowUrl(sdkUrl, flowType, flow)).toBe( + "http://example.com/self-service/login/browser?return_to=http%3A%2F%2Fexample.com%2Freturn", + ) + }) + + xit("should return sdkUrl with flowType if return_to is not present", () => { + const sdkUrl = "http://example.com" + const flowType = "login" + const flow = {} + + // Not sure how to mock this. + window.location.href = "http://example.com" + expect(initFlowUrl(sdkUrl, flowType, flow)).toBe( + "http://example.com/self-service/login/browser", + ) + }) + }) +}) diff --git a/packages/elements-react/src/theme/default/utils/url.ts b/packages/elements-react/src/theme/default/utils/url.ts index d2d63514..ffd95043 100644 --- a/packages/elements-react/src/theme/default/utils/url.ts +++ b/packages/elements-react/src/theme/default/utils/url.ts @@ -1,3 +1,6 @@ +// Copyright © 2024 Ory Corp +// SPDX-License-Identifier: Apache-2.0 + export function restartFlowUrl( flow: { request_url?: string; return_to?: string }, fallback: string,