X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/8095c4a7852131043b682b809ed78ca65386dd30..6ddbc50bc04b9bedce3f54cf69660fc819fce67a:/src/common/redirect-to.ts diff --git a/src/common/redirect-to.ts b/src/common/redirect-to.ts index f5ece21b..77be742f 100644 --- a/src/common/redirect-to.ts +++ b/src/common/redirect-to.ts @@ -7,13 +7,15 @@ import { Config } from './config'; const REDIRECT_TO_KEY = 'redirectTo'; export const storeRedirects = () => { - if (window.location.href.indexOf(REDIRECT_TO_KEY) > -1) { - const { location: { href }, localStorage } = window; - const redirectUrl = href.split(`${REDIRECT_TO_KEY}=`)[1]; + let redirectUrl; + const { location: { href }, localStorage } = window; - if (localStorage) { - localStorage.setItem(REDIRECT_TO_KEY, redirectUrl); - } + if (href.indexOf(REDIRECT_TO_KEY) > -1) { + redirectUrl = href.split(`${REDIRECT_TO_KEY}=`)[1]; + } + + if (localStorage && redirectUrl) { + localStorage.setItem(REDIRECT_TO_KEY, redirectUrl); } }; @@ -24,6 +26,7 @@ export const handleRedirects = (token: string, config: Config) => { if (localStorage && localStorage.getItem(REDIRECT_TO_KEY)) { const redirectUrl = localStorage.getItem(REDIRECT_TO_KEY); localStorage.removeItem(REDIRECT_TO_KEY); + if (redirectUrl) { const sep = redirectUrl.indexOf("?") > -1 ? "&" : "?"; window.location.href = `${keepWebServiceUrl}${redirectUrl}${sep}api_token=${token}`;