17722: When saving or removing data from storage, clear both 17722-clear-localstorage
authorPeter Amstutz <peter.amstutz@curii.com>
Tue, 25 May 2021 20:13:08 +0000 (16:13 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Tue, 25 May 2021 20:13:08 +0000 (16:13 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

src/services/auth-service/auth-service.ts

index bd4bc1969c5004d1506f39b3d5a233d748d2fa57..355cef42ec32cdc195447c978466c546ae02ce64 100644 (file)
@@ -51,6 +51,7 @@ export class AuthService {
     }
 
     public saveApiToken(token: string) {
+        this.removeApiToken();
         this.getStorage().setItem(API_TOKEN_KEY, token);
         const sp = token.split('/');
         if (sp.length === 3) {
@@ -59,7 +60,8 @@ export class AuthService {
     }
 
     public removeTargetURL() {
-        this.getStorage().removeItem(TARGET_URL);
+        localStorage.removeItem(TARGET_URL);
+        sessionStorage.removeItem(TARGET_URL);
     }
 
     public getTargetURL() {
@@ -67,7 +69,8 @@ export class AuthService {
     }
 
     public removeApiToken() {
-        this.getStorage().removeItem(API_TOKEN_KEY);
+        localStorage.removeItem(API_TOKEN_KEY);
+        sessionStorage.removeItem(API_TOKEN_KEY);
     }
 
     public getApiToken() {
@@ -83,16 +86,18 @@ export class AuthService {
     }
 
     public removeUser() {
-        this.getStorage().removeItem(USER_EMAIL_KEY);
-        this.getStorage().removeItem(USER_FIRST_NAME_KEY);
-        this.getStorage().removeItem(USER_LAST_NAME_KEY);
-        this.getStorage().removeItem(USER_UUID_KEY);
-        this.getStorage().removeItem(USER_OWNER_UUID_KEY);
-        this.getStorage().removeItem(USER_IS_ADMIN);
-        this.getStorage().removeItem(USER_IS_ACTIVE);
-        this.getStorage().removeItem(USER_USERNAME);
-        this.getStorage().removeItem(USER_PREFS);
-        this.getStorage().removeItem(TARGET_URL);
+        [localStorage, sessionStorage].forEach((storage) => {
+            storage.removeItem(USER_EMAIL_KEY);
+            storage.removeItem(USER_FIRST_NAME_KEY);
+            storage.removeItem(USER_LAST_NAME_KEY);
+            storage.removeItem(USER_UUID_KEY);
+            storage.removeItem(USER_OWNER_UUID_KEY);
+            storage.removeItem(USER_IS_ADMIN);
+            storage.removeItem(USER_IS_ACTIVE);
+            storage.removeItem(USER_USERNAME);
+            storage.removeItem(USER_PREFS);
+            storage.removeItem(TARGET_URL);
+        });
     }
 
     public login(uuidPrefix: string, homeCluster: string, loginCluster: string, remoteHosts: { [key: string]: string }) {
@@ -145,11 +150,13 @@ export class AuthService {
     }
 
     public saveSessions(sessions: Session[]) {
+        this.removeSessions();
         this.getStorage().setItem("sessions", JSON.stringify(sessions));
     }
 
     public removeSessions() {
-        this.getStorage().removeItem("sessions");
+        localStorage.removeItem("sessions");
+        sessionStorage.removeItem("sessions");
     }
 
     public buildSessions(cfg: Config, user?: User) {