16812: Handoff token using query param
[arvados-workbench2.git] / src / common / redirect-to.ts
index 86fac71cbae8ab7adb27354ee7a351e34c7c72e3..7cb0d5805577794fae00148c5fd42f24d360cc8e 100644 (file)
@@ -10,20 +10,23 @@ export const storeRedirects = () => {
     if (window.location.href.indexOf(REDIRECT_TO_KEY) > -1) {
         const { location: { href }, sessionStorage } = window;
         const redirectUrl = href.split(`${REDIRECT_TO_KEY}=`)[1];
-        
+
         if (sessionStorage) {
             sessionStorage.setItem(REDIRECT_TO_KEY, redirectUrl);
         }
     }
 };
 
-export const handleRedirects = (config: Config) => {
+export const handleRedirects = (token: string, config: Config) => {
     const { sessionStorage } = window;
     const { keepWebServiceUrl } = config;
 
     if (sessionStorage && sessionStorage.getItem(REDIRECT_TO_KEY)) {
         const redirectUrl = sessionStorage.getItem(REDIRECT_TO_KEY);
         sessionStorage.removeItem(REDIRECT_TO_KEY);
-        window.location.href = `${keepWebServiceUrl}${redirectUrl}`;
+        if (redirectUrl) {
+            const sep = redirectUrl.indexOf("?") > -1 ? "&" : "?";
+            window.location.href = `${keepWebServiceUrl}${redirectUrl}${sep}api_token=${token}`;
+        }
     }
-};
\ No newline at end of file
+};