From afbdf41dcafc795f036593fb9ea59d3a357806a6 Mon Sep 17 00:00:00 2001 From: BermetK123 Date: Wed, 15 Jan 2025 09:07:47 -0600 Subject: [PATCH] Update validate-redirect-url.js Solving the failed tests --- .../utils/validate-redirect-url.js | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/blocks/identity-block/utils/validate-redirect-url.js b/blocks/identity-block/utils/validate-redirect-url.js index c23c7b6d6..2acbd5696 100644 --- a/blocks/identity-block/utils/validate-redirect-url.js +++ b/blocks/identity-block/utils/validate-redirect-url.js @@ -1,20 +1,35 @@ const validateURL = (url) => { - if (!url) return null; + if (!url) return null; - try { - const urlObject = new URL(url, window.location.origin); + try { + const urlObject = new URL(url, window.location.origin); + console.log("urlObject " + urlObject.origin) + console.log("window " +window.location.origin) - if (urlObject.origin === window.location.origin) { - return urlObject.pathname; + if (urlObject.origin === window.location.origin) { + console.log("urlObject pth " + urlObject.pathname); + + if(urlObject.pathname === "/"){ + return urlObject.pathname + } + + if(urlObject.pathname !== "/"){ + return `${urlObject.origin}${urlObject.pathname}` + } + } + + sessionStorage.setItem("ArcXP_redirectUrl", "/"); + return "/"; + } catch (error) { + const storedRedirect = sessionStorage.getItem("ArcXP_redirectUrl"); + if (storedRedirect && storedRedirect.startsWith("/")) { + return storedRedirect; } - } catch (e) { + // Default to "/" sessionStorage.setItem("ArcXP_redirectUrl", "/"); return "/"; - } - - sessionStorage.setItem("ArcXP_redirectUrl", "/"); - return "/"; + } }; -export default validateURL; +export default validateURL; \ No newline at end of file