Merge branch '18965-login-flow-destination' into main. Closes #18965
authorStephen Smith <stephen@curii.com>
Fri, 22 Jul 2022 20:51:25 +0000 (16:51 -0400)
committerStephen Smith <stephen@curii.com>
Fri, 22 Jul 2022 20:51:25 +0000 (16:51 -0400)
Arvados-DCO-1.1-Signed-off-by: Stephen Smith <stephen@curii.com>

src/services/auth-service/auth-service.ts
src/views-components/login-form/login-form.tsx

index 548dbcaa13d6238d343560dc459ba5cb35e1ba7b..52bfa29ecae21bb2a86967d0dbd63cd9b072f9fd 100644 (file)
@@ -68,13 +68,16 @@ export class AuthService {
         }
     }
 
+    public setTargetUrl(url: string) {
+        localStorage.setItem(TARGET_URL, url);
+    }
+
     public removeTargetURL() {
         localStorage.removeItem(TARGET_URL);
-        sessionStorage.removeItem(TARGET_URL);
     }
 
     public getTargetURL() {
-        return this.getStorage().getItem(TARGET_URL);
+        return localStorage.getItem(TARGET_URL);
     }
 
     public removeApiToken() {
@@ -113,7 +116,7 @@ export class AuthService {
         const currentUrl = `${window.location.protocol}//${window.location.host}/token`;
         const homeClusterHost = remoteHosts[homeCluster];
         const rd = new URL(window.location.href);
-        this.getStorage().setItem(TARGET_URL, rd.pathname + rd.search);
+        this.setTargetUrl(rd.pathname + rd.search);
         window.location.assign(`https://${homeClusterHost}/login?${(uuidPrefix !== homeCluster && homeCluster !== loginCluster) ? "remote=" + uuidPrefix + "&" : ""}return_to=${currentUrl}`);
     }
 
index aac1364207420247b0e620b3ee3b2679cda9d08e..3aa9e3f25aeb8ed1c6646765051596cb16ff00dd 100644 (file)
@@ -12,6 +12,7 @@ import { AxiosPromise } from 'axios';
 import { DispatchProp } from 'react-redux';
 import { saveApiToken } from 'store/auth/auth-action';
 import { navigateToRootProject } from 'store/navigation/navigation-action';
+import { replace } from 'react-router-redux';
 
 type CssRules = 'root' | 'loginBtn' | 'card' | 'wrapper' | 'progress';
 
@@ -87,8 +88,11 @@ export const LoginForm = withStyles(styles)(
                 setSubmitting(false);
                 if (response.data.uuid && response.data.api_token) {
                     const apiToken = `v2/${response.data.uuid}/${response.data.api_token}`;
+                    const rd = new URL(window.location.href);
+                    const rdUrl = rd.pathname + rd.search;
                     dispatch<any>(saveApiToken(apiToken)).finally(
-                        () => dispatch(navigateToRootProject));
+                        () => rdUrl === '/' ? dispatch(navigateToRootProject) : dispatch(replace(rdUrl))
+                    );
                 } else {
                     setError(true);
                     setHelperText(response.data.message || 'Please try again');