File tree Expand file tree Collapse file tree 2 files changed +22
-10
lines changed Expand file tree Collapse file tree 2 files changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -172,12 +172,11 @@ const deleteSession = async (accountId) => {
172172 parseOutput: false,
173173 sdk: client
174174 })
175-
176- globalConfig.removeSession(accountId);
177175 } catch (e) {
178176 error('Unable to log out, removing locally saved session information')
177+ } finally {
178+ globalConfig.removeSession(accountId);
179179 }
180- globalConfig.removeSession(accountId);
181180}
182181
183182const logout = new Command("logout")
@@ -195,6 +194,7 @@ const logout = new Command("logout")
195194 }
196195 if (sessions.length === 1) {
197196 await deleteSession(current);
197+ globalConfig.setCurrentSession('');
198198 success("Logging out");
199199
200200 return;
@@ -216,6 +216,8 @@ const logout = new Command("logout")
216216 globalConfig.setCurrentSession(accountId);
217217
218218 success(`Current account is ${accountId}`);
219+ } else if (remainingSessions.length === 0) {
220+ globalConfig.setCurrentSession('');
219221 }
220222
221223 success("Logging out");
Original file line number Diff line number Diff line change @@ -681,15 +681,25 @@ class Global extends Config {
681681
682682 getSessions() {
683683 const sessions = Object.keys(this.data).filter((key) => !Global.IGNORE_ATTRIBUTES.includes(key))
684+ const current = this.getCurrentSession();
684685
685- return sessions.map((session) => {
686-
687- return {
688- id: session,
689- endpoint: this.data[session][Global.PREFERENCE_ENDPOINT],
690- email: this.data[session][Global.PREFERENCE_EMAIL]
686+ const sessionMap = new Map();
687+
688+ sessions.forEach((sessionId) => {
689+ const email = this.data[sessionId][Global.PREFERENCE_EMAIL];
690+ const endpoint = this.data[sessionId][Global.PREFERENCE_ENDPOINT];
691+ const key = `${email}|${endpoint}`;
692+
693+ if (sessionId === current || !sessionMap.has(key)) {
694+ sessionMap.set(key, {
695+ id: sessionId,
696+ endpoint: this.data[sessionId][Global.PREFERENCE_ENDPOINT],
697+ email: this.data[sessionId][Global.PREFERENCE_EMAIL]
698+ });
691699 }
692- })
700+ });
701+
702+ return Array.from(sessionMap.values());
693703 }
694704
695705 addSession(session, data) {
You can’t perform that action at this time.
0 commit comments