Skip to content

Commit cb4d04e

Browse files
revert auth changes
1 parent 20324f5 commit cb4d04e

2 files changed

Lines changed: 25 additions & 12 deletions

File tree

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,25 @@ 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 {
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) {
121+
} else if (result.error_code === 294) {
122+
const tfToken = await this.handleOTPFlow(tfaToken, loginPayload);
123+
128124
try {
129-
const tfToken = await this.handleOTPFlow(tfaToken, loginPayload);
130125
resolve(await this.login(email, password, tfToken));
131126
} catch (error) {
132127
log.debug('Login with TFA token failed.', { module: 'auth-handler', error });
133128
cliux.print('CLI_AUTH_2FA_FAILED', { color: 'red' });
134129
reject(error);
135130
}
136131
} else {
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);
132+
log.debug('Login failed: no user found.', { module: 'auth-handler', result });
133+
reject(new Error(messageHandler.parse('CLI_AUTH_LOGIN_NO_USER')));
140134
}
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' });
141140
});
142141
} else {
143142
const hasEmail = !!email;
@@ -204,7 +203,7 @@ class AuthHandler {
204203
.catch((error: Error) => {
205204
log.debug('Token validation failed.', { module: 'auth-handler', error: error.message });
206205
cliux.print('CLI_AUTH_TOKEN_VALIDATION_FAILED', { color: 'yellow' });
207-
reject(error);
206+
handleAndLogError(error, { module: 'auth-handler' });
208207
});
209208
} else {
210209
log.debug('Token validation failed: no auth token provided.', { module: 'auth-handler' });

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ 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+
90104
if (secret) {
91105
try {
92106
const code = this.generateMFACode(secret);

0 commit comments

Comments
 (0)