Skip to content

Commit a8f3475

Browse files
committed
Fix: Fixed the 2FA issue
1 parent 72234d7 commit a8f3475

File tree

7 files changed

+23
-36
lines changed

7 files changed

+23
-36
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-auth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@contentstack/cli-auth",
33
"description": "Contentstack CLI plugin for authentication activities",
4-
"version": "2.0.0-beta.2",
4+
"version": "2.0.0-beta.3",
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"scripts": {

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,26 @@ class AuthHandler {
118118
if (result.user) {
119119
log.debug('Login successful, user found', { module: 'auth-handler', userEmail: result.user.email });
120120
resolve(result.user as User);
121-
} else if (result.error_code === 294) {
122-
const tfToken = await this.handleOTPFlow(tfaToken, loginPayload);
123-
121+
} else {
122+
log.debug('Login failed: no user found.', { module: 'auth-handler', result });
123+
reject(new Error(messageHandler.parse('CLI_AUTH_LOGIN_NO_USER')));
124+
}
125+
})
126+
.catch(async (error: any) => {
127+
if (error.errorCode === 294) {
124128
try {
129+
const tfToken = await this.handleOTPFlow(tfaToken, loginPayload);
125130
resolve(await this.login(email, password, tfToken));
126131
} catch (error) {
127132
log.debug('Login with TFA token failed.', { module: 'auth-handler', error });
128133
cliux.print('CLI_AUTH_2FA_FAILED', { color: 'red' });
129134
reject(error);
130135
}
131136
} else {
132-
log.debug('Login failed: no user found.', { module: 'auth-handler', result });
133-
reject(new Error(messageHandler.parse('CLI_AUTH_LOGIN_NO_USER')));
137+
log.debug('Login API call failed.', { module: 'auth-handler', error: error?.errorMessage || error });
138+
cliux.print('CLI_AUTH_LOGIN_FAILED', { color: 'yellow' });
139+
reject(error);
134140
}
135-
})
136-
.catch((error: any) => {
137-
log.debug('Login API call failed.', { module: 'auth-handler', error: error?.errorMessage || error });
138-
cliux.print('CLI_AUTH_LOGIN_FAILED', { color: 'yellow' });
139-
handleAndLogError(error, { module: 'auth-handler' });
140141
});
141142
} else {
142143
const hasEmail = !!email;
@@ -203,7 +204,7 @@ class AuthHandler {
203204
.catch((error: Error) => {
204205
log.debug('Token validation failed.', { module: 'auth-handler', error: error.message });
205206
cliux.print('CLI_AUTH_TOKEN_VALIDATION_FAILED', { color: 'yellow' });
206-
handleAndLogError(error, { module: 'auth-handler' });
207+
reject(error);
207208
});
208209
} else {
209210
log.debug('Token validation failed: no auth token provided.', { module: 'auth-handler' });
@@ -213,4 +214,4 @@ class AuthHandler {
213214
}
214215
}
215216

216-
export default new AuthHandler();
217+
export default new AuthHandler();

packages/contentstack-auth/src/utils/mfa-handler.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,6 @@ class MFAHandler {
8787
}
8888
}
8989

90-
if (!secret) {
91-
log.debug('Checking stored MFA secret', { module: 'mfa-handler' });
92-
const mfaConfig = configHandler.get('mfa');
93-
if (mfaConfig?.secret) {
94-
try {
95-
secret = this.encrypter.decrypt(mfaConfig.secret);
96-
source = 'stored configuration';
97-
} catch (error) {
98-
log.debug('Failed to decrypt stored MFA secret', { module: 'mfa-handler', error });
99-
handleAndLogError(error, { module: 'mfa-handler' }, messageHandler.parse('CLI_AUTH_MFA_DECRYPT_FAILED'));
100-
}
101-
}
102-
}
103-
10490
if (secret) {
10591
try {
10692
const code = this.generateMFACode(secret);

packages/contentstack-export/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"winston": "^3.17.0"
2222
},
2323
"devDependencies": {
24-
"@contentstack/cli-auth": "~2.0.0-beta.1",
24+
"@contentstack/cli-auth": "~2.0.0-beta.3",
2525
"@contentstack/cli-config": "~1.18.0",
2626
"@contentstack/cli-dev-dependencies": "~1.3.1",
2727
"@oclif/plugin-help": "^6.2.28",

packages/contentstack/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@contentstack/cli",
33
"description": "Command-line tool (CLI) to interact with Contentstack",
4-
"version": "2.0.0-beta.5",
4+
"version": "2.0.0-beta.6",
55
"author": "Contentstack",
66
"bin": {
77
"csdx": "./bin/run.js"
@@ -23,7 +23,7 @@
2323
},
2424
"dependencies": {
2525
"@contentstack/cli-audit": "~2.0.0-beta.2",
26-
"@contentstack/cli-auth": "~2.0.0-beta.2",
26+
"@contentstack/cli-auth": "~2.0.0-beta.3",
2727
"@contentstack/cli-cm-bootstrap": "~2.0.0-beta.4",
2828
"@contentstack/cli-cm-branches": "~1.6.3",
2929
"@contentstack/cli-cm-bulk-publish": "~1.10.6",

pnpm-lock.yaml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)