File tree Expand file tree Collapse file tree
contentstack-auth/src/commands/auth Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77 flags ,
88 authHandler as oauthHandler ,
99 managementSDKClient ,
10- isAuthenticated ,
1110} from '@contentstack/cli-utilities' ;
1211
1312import { authHandler } from '../../utils' ;
@@ -50,14 +49,19 @@ export default class LogoutCommand extends Command {
5049 try {
5150 const managementAPIClient = await managementSDKClient ( { host : this . cmaHost , skipTokenValidity : true } ) ;
5251 authHandler . client = managementAPIClient ;
53- if ( isAuthenticated ( ) ) {
52+ if ( ( await oauthHandler . isAuthenticated ( ) ) && ( await oauthHandler . isAuthorisationTypeBasic ( ) ) ) {
5453 if ( confirm === true ) {
5554 cliux . loader ( 'CLI_AUTH_LOGOUT_LOADER_START' ) ;
5655 await authHandler . logout ( configHandler . get ( 'authtoken' ) ) ;
5756 cliux . loader ( '' ) ;
5857 logger . info ( 'successfully logged out' ) ;
5958 cliux . success ( 'CLI_AUTH_LOGOUT_SUCCESS' ) ;
6059 }
60+ } else {
61+ cliux . loader ( 'CLI_AUTH_LOGOUT_LOADER_START' ) ;
62+ cliux . loader ( '' ) ;
63+ logger . info ( 'successfully logged out' ) ;
64+ cliux . success ( 'CLI_AUTH_LOGOUT_SUCCESS' ) ;
6165 }
6266 } catch ( error ) {
6367 let errorMessage = '' ;
Original file line number Diff line number Diff line change @@ -384,6 +384,18 @@ class AuthHandler {
384384 ) ;
385385 }
386386
387+ async getAuthorisationType ( ) : Promise < any > {
388+ return configHandler . get ( this . authorisationTypeKeyName ) ? configHandler . get ( this . authorisationTypeKeyName ) : false ;
389+ }
390+
391+ async isAuthorisationTypeBasic ( ) : Promise < boolean > {
392+ return configHandler . get ( this . authorisationTypeKeyName ) === this . authorisationTypeAUTHValue ? true : false ;
393+ }
394+
395+ async isAuthorisationTypeOAuth ( ) : Promise < boolean > {
396+ return configHandler . get ( this . authorisationTypeKeyName ) === this . authorisationTypeOAUTHValue ? true : false ;
397+ }
398+
387399 checkExpiryAndRefresh = ( force : boolean = false ) => this . compareOAuthExpiry ( force ) ;
388400
389401 async compareOAuthExpiry ( force : boolean = false ) {
Original file line number Diff line number Diff line change @@ -37,6 +37,9 @@ declare class AuthHandler {
3737 isAuthenticated ( ) : Promise < boolean > ;
3838 checkExpiryAndRefresh : ( force ?: boolean ) => Promise < void | object > ;
3939 compareOAuthExpiry ( force ?: boolean ) : Promise < void | object > ;
40+ getAuthorisationType ( ) : Promise < boolean > ;
41+ isAuthorisationTypeBasic ( ) : Promise < boolean > ;
42+ isAuthorisationTypeOAuth ( ) : Promise < boolean > ;
4043}
4144declare const _default : AuthHandler ;
4245export default _default ;
You can’t perform that action at this time.
0 commit comments