@@ -11,8 +11,8 @@ const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accoun
11
11
12
12
const DEFAULT_ENDPOINT = 'https://cloud.appwrite.io/v1';
13
13
14
- const loginCommand = async ({ selfHosted }) => {
15
- const answers = await inquirer.prompt(questionsLogin);
14
+ const loginCommand = async ({ selfHosted, email, password, endpoint, mfa, code }) => {
15
+ const answers = email && password ? { email, password } : await inquirer.prompt(questionsLogin);
16
16
17
17
if (answers.method === 'select') {
18
18
const accountId = answers.accountId;
@@ -36,7 +36,7 @@ const loginCommand = async ({ selfHosted }) => {
36
36
globalConfig.setEndpoint(DEFAULT_ENDPOINT);
37
37
38
38
if (selfHosted) {
39
- const selfHostedAnswers = await inquirer.prompt(questionGetEndpoint);
39
+ const selfHostedAnswers = endpoint ? { endpoint } : await inquirer.prompt(questionGetEndpoint);
40
40
41
41
globalConfig.setEndpoint(selfHostedAnswers.endpoint);
42
42
}
@@ -61,15 +61,15 @@ const loginCommand = async ({ selfHosted }) => {
61
61
});
62
62
} catch (error) {
63
63
if (error.response === 'user_more_factors_required') {
64
- const { factor } = await inquirer.prompt(questionsListFactors);
64
+ const { factor } = mfa ? { factor: mfa } : await inquirer.prompt(questionsListFactors);
65
65
66
66
const challenge = await accountCreateMfaChallenge({
67
67
factor,
68
68
parseOutput: false,
69
69
sdk: client
70
70
});
71
71
72
- const { otp } = await inquirer.prompt(questionsMfaChallenge);
72
+ const { otp } = code ? { otp: code } : await inquirer.prompt(questionsMfaChallenge);
73
73
74
74
await accountUpdateMfaChallenge({
75
75
challengeId: challenge.$id,
@@ -135,6 +135,11 @@ const whoami = new Command("whoami")
135
135
const login = new Command("login")
136
136
.description(commandDescriptions['login'])
137
137
.option(`-sh, --self-hosted`, `Flag for enabling custom endpoint for self hosted instances`)
138
+ .option(`--email [email]`, `User email`)
139
+ .option(`--password [password]`, `User password`)
140
+ .option(`--endpoint [endpoint]`, `Appwrite endpoint for self hosted instances`)
141
+ .option(`--mfa [factor]`, `Multi-factor authentication login factor: totp, email, phone or recoveryCode`)
142
+ .option(`--code [code]`, `Multi-factor code`)
138
143
.configureHelp({
139
144
helpWidth: process.stdout.columns || 80
140
145
})
0 commit comments