@@ -10,7 +10,6 @@ import {
1010 commandDescriptions ,
1111 error ,
1212 parse ,
13- hint ,
1413 log ,
1514 drawTable ,
1615 cliConfig ,
@@ -27,6 +26,17 @@ import {
2726
2827export { loginCommand } ;
2928
29+ const logMessages = {
30+ noActiveSessions : "No active sessions found." ,
31+ logoutFailure : ( errors : string [ ] = [ ] ) : string => {
32+ const uniqueErrors = [ ...new Set ( errors ) ] ;
33+ const details = uniqueErrors . length ? `: ${ uniqueErrors . join ( "; " ) } ` : "" ;
34+ return `Could not log out because the server session could not be revoked${ details } . Kept local session data.` ;
35+ } ,
36+ logoutSuccess : "Logged out successfully" ,
37+ clientConfigUpdated : "Client configuration updated" ,
38+ } as const ;
39+
3040export const whoami = new Command ( "whoami" )
3141 . description ( commandDescriptions [ "whoami" ] )
3242 . action (
@@ -101,38 +111,37 @@ export const logout = new Command("logout")
101111 const originalCurrent = current ;
102112
103113 if ( current === "" || ! sessions . length ) {
104- log ( "No active sessions found." ) ;
114+ log ( logMessages . noActiveSessions ) ;
105115 return ;
106116 }
107117 if ( sessions . length === 1 ) {
108- const { failed, failedIds } = await logoutSessions (
118+ const { failed, failedIds, errors } = await logoutSessions (
109119 planSessionLogout ( [ current ] ) ,
110120 ) ;
111121
112122 if ( failed > 0 ) {
113123 restoreCurrentSessionFallback ( originalCurrent , failedIds ) ;
114- hint (
115- "Could not reach server for all sessions; kept local session data" ,
116- ) ;
124+ error ( logMessages . logoutFailure ( errors ) ) ;
125+ return ;
117126 } else {
118127 globalConfig . setCurrentSession ( "" ) ;
119128 }
120- success ( "Logged out successfully" ) ;
129+ success ( logMessages . logoutSuccess ) ;
121130
122131 return ;
123132 }
124133
125134 const answers = await inquirer . prompt ( questionsLogout ) ;
135+ let logoutFailed = false ;
126136
127137 if ( answers . accounts ?. length ) {
128- const { failed } = await logoutSessions (
138+ const { failed, errors } = await logoutSessions (
129139 planSessionLogout ( answers . accounts as string [ ] ) ,
130140 ) ;
131141
132142 if ( failed > 0 ) {
133- hint (
134- "Could not reach server for all sessions; kept local session data" ,
135- ) ;
143+ logoutFailed = true ;
144+ error ( logMessages . logoutFailure ( errors ) ) ;
136145 }
137146 }
138147
@@ -149,16 +158,20 @@ export const logout = new Command("logout")
149158 remainingSessions [ 0 ] ;
150159 globalConfig . setCurrentSession ( nextSession . id ) ;
151160
152- success (
153- nextSession . email
154- ? `Switched to ${ nextSession . email } `
155- : `Switched to session at ${ nextSession . endpoint } ` ,
156- ) ;
161+ if ( ! logoutFailed ) {
162+ success (
163+ nextSession . email
164+ ? `Switched to ${ nextSession . email } `
165+ : `Switched to session at ${ nextSession . endpoint } ` ,
166+ ) ;
167+ }
157168 } else if ( remainingSessions . length === 0 ) {
158169 globalConfig . setCurrentSession ( "" ) ;
159170 }
160171
161- success ( "Logged out successfully" ) ;
172+ if ( ! logoutFailed ) {
173+ success ( logMessages . logoutSuccess ) ;
174+ }
162175 } ) ,
163176 ) ;
164177
@@ -288,22 +301,21 @@ export const client = new Command("client")
288301
289302 if ( reset !== undefined ) {
290303 const originalCurrent = globalConfig . getCurrentSession ( ) ;
291- const { failed, failedIds } = await logoutSessions (
304+ const { failed, failedIds, errors } = await logoutSessions (
292305 globalConfig . getSessionIds ( ) ,
293306 ) ;
294307
295308 if ( failed > 0 ) {
296309 restoreCurrentSessionFallback ( originalCurrent , failedIds ) ;
297- hint (
298- "Could not reach server for all sessions; kept local session data" ,
299- ) ;
310+ error ( logMessages . logoutFailure ( errors ) ) ;
311+ return ;
300312 } else {
301313 globalConfig . setCurrentSession ( "" ) ;
302314 }
303315 }
304316
305317 if ( ! debug ) {
306- success ( "Setting client" ) ;
318+ success ( logMessages . clientConfigUpdated ) ;
307319 }
308320 } ,
309321 ) ,
0 commit comments