Merge branch '15530-wb2-logincluster' refs #15530
[arvados-workbench2.git] / src / services / auth-service / auth-service.ts
index a80d89ba146f374f329ff62f179217997fd34e6f..da96f1629b2fc9e3cf76ba91c3215df43bd17666 100644 (file)
@@ -114,10 +114,10 @@ export class AuthService {
         localStorage.removeItem(USER_PREFS);
     }
 
-    public login(uuidPrefix: string, homeCluster: string, remoteHosts: { [key: string]: string }) {
+    public login(uuidPrefix: string, homeCluster: string, loginCluster: string, remoteHosts: { [key: string]: string }) {
         const currentUrl = `${window.location.protocol}//${window.location.host}/token`;
         const homeClusterHost = remoteHosts[homeCluster];
-        window.location.assign(`https://${homeClusterHost}/login?${uuidPrefix !== homeCluster ? "remote=" + uuidPrefix + "&" : ""}return_to=${currentUrl}`);
+        window.location.assign(`https://${homeClusterHost}/login?${(uuidPrefix !== homeCluster && homeCluster !== loginCluster) ? "remote=" + uuidPrefix + "&" : ""}return_to=${currentUrl}`);
     }
 
     public logout() {
@@ -183,7 +183,12 @@ export class AuthService {
             active: true,
             status: SessionStatus.VALIDATED
         } as Session;
-        const localSessions = this.getSessions();
+        const localSessions = this.getSessions().map(s => ({
+            ...s,
+            active: false,
+            status: SessionStatus.INVALIDATED
+        }));
+
         const cfgSessions = Object.keys(cfg.remoteHosts).map(clusterId => {
             const remoteHost = cfg.remoteHosts[clusterId];
             return {
@@ -199,8 +204,9 @@ export class AuthService {
             } as Session;
         });
         const sessions = [currentSession]
+            .concat(cfgSessions)
             .concat(localSessions)
-            .concat(cfgSessions);
+            .filter((r: Session) => r.clusterId !== "*");
 
         const uniqSessions = uniqBy(sessions, 'clusterId');