Skip to content

Commit

Permalink
Merge branch 'arc-themes-release-version-2.5.3' into ASUB-8965_Fix_sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeganderson authored Feb 6, 2025
2 parents 40fbf60 + 7de2a9b commit 181d429
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions blocks/identity-block/utils/validate-redirect-url.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
const validateURL = (url) => {
if (!url) return null;
const validationRegEx = /^\/[^/].*$/;
const valid = validationRegEx.test(url);

if (valid) {
return `${window.location.origin}${url}`;
}
try {
const urlObject = new URL(url, window.location.origin);

if (url === "/") {
return url;
}
if (urlObject.origin === window.location.origin) {

if(urlObject.pathname === "/"){
return urlObject.pathname
}

const urlLocation = new URL(url);
if(urlObject.pathname !== "/"){
return urlObject.toString();
}
}
sessionStorage.setItem("ArcXP_redirectUrl", "/");
return "/";

} catch (error) {
const storedRedirect = sessionStorage.getItem("ArcXP_redirectUrl");
if (storedRedirect && storedRedirect.startsWith("/")) {
return storedRedirect;
}

if (urlLocation.origin === window.location.origin) {
return url;
// Default to "/"
sessionStorage.setItem("ArcXP_redirectUrl", "/");
return "/";
}

sessionStorage.setItem("ArcXP_redirectUrl", "/");
return "/";
};

export default validateURL;
export default validateURL;

0 comments on commit 181d429

Please sign in to comment.