19715: Add preserve url location flag to logout action - set to true for autologout
[arvados-workbench2.git] / src / services / auth-service / auth-service.ts
index 52bfa29ecae21bb2a86967d0dbd63cd9b072f9fd..b530e4cd3e8d4933cf3e445fe6f306f8994b6d4c 100644 (file)
@@ -120,9 +120,13 @@ export class AuthService {
         window.location.assign(`https://${homeClusterHost}/login?${(uuidPrefix !== homeCluster && homeCluster !== loginCluster) ? "remote=" + uuidPrefix + "&" : ""}return_to=${currentUrl}`);
     }
 
-    public logout(expireToken: string) {
-        const currentUrl = `${window.location.protocol}//${window.location.host}`;
-        window.location.assign(`${this.baseUrl || ""}/logout?api_token=${expireToken}&return_to=${currentUrl}`);
+    public logout(expireToken: string, preservePath: boolean) {
+        const fullUrl = new URL(window.location.href);
+        const wbBase = `${fullUrl.protocol}//${fullUrl.host}`;
+        const wbPath = fullUrl.pathname + fullUrl.search;
+        const returnTo = `${wbBase}${preservePath ? wbPath : ''}`
+
+        window.location.assign(`${this.baseUrl || ""}/logout?api_token=${expireToken}&return_to=${returnTo}`);
     }
 
     public getUserDetails = (showErrors?: boolean): Promise<User> => {