Skip to content

Commit 5e4434b

Browse files
committed
Resolved logout issue for oauth
1 parent e468345 commit 5e4434b

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

packages/contentstack-auth/src/commands/auth/logout.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
flags,
88
authHandler as oauthHandler,
99
managementSDKClient,
10-
isAuthenticated,
1110
} from '@contentstack/cli-utilities';
1211

1312
import { 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 = '';

packages/contentstack-utilities/src/auth-handler.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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) {

packages/contentstack-utilities/types/auth-handler.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}
4144
declare const _default: AuthHandler;
4245
export default _default;

0 commit comments

Comments
 (0)