16005: Removed unused functions
[arvados-workbench2.git] / src / common / redirect-to.ts
index 54268c24c8114052abb4faeeb880b5cd00b0ce2b..77be742f877ce62477a6e3439eb6c020e41821b0 100644 (file)
@@ -2,25 +2,34 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
+import { Config } from './config';
+
 const REDIRECT_TO_KEY = 'redirectTo';
 
 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);
-        }
+    let redirectUrl;
+    const { location: { href }, localStorage } = window;
+
+    if (href.indexOf(REDIRECT_TO_KEY) > -1) {
+        redirectUrl = href.split(`${REDIRECT_TO_KEY}=`)[1];
+    }
+
+    if (localStorage && redirectUrl) {
+        localStorage.setItem(REDIRECT_TO_KEY, redirectUrl);
     }
 };
 
-export const handleRedirects = (token: string) => {
-    const { sessionStorage } = window;
+export const handleRedirects = (token: string, config: Config) => {
+    const { localStorage } = window;
+    const { keepWebServiceUrl } = config;
+
+    if (localStorage && localStorage.getItem(REDIRECT_TO_KEY)) {
+        const redirectUrl = localStorage.getItem(REDIRECT_TO_KEY);
+        localStorage.removeItem(REDIRECT_TO_KEY);
 
-    if (sessionStorage && sessionStorage.getItem(REDIRECT_TO_KEY)) {
-        const redirectUrl = sessionStorage.getItem(REDIRECT_TO_KEY);
-        sessionStorage.removeItem(REDIRECT_TO_KEY);
-        window.location.href = `${redirectUrl}?api_token=${token}`;
+        if (redirectUrl) {
+            const sep = redirectUrl.indexOf("?") > -1 ? "&" : "?";
+            window.location.href = `${keepWebServiceUrl}${redirectUrl}${sep}api_token=${token}`;
+        }
     }
-};
\ No newline at end of file
+};