Skip to content

Commit 705647d

Browse files
committed
chore(cli): Adding headless login
1 parent cf2ce7d commit 705647d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

templates/cli/lib/commands/generic.js.twig

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accoun
1111

1212
const DEFAULT_ENDPOINT = 'https://cloud.appwrite.io/v1';
1313

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);
1616

1717
if (answers.method === 'select') {
1818
const accountId = answers.accountId;
@@ -36,7 +36,7 @@ const loginCommand = async ({ selfHosted }) => {
3636
globalConfig.setEndpoint(DEFAULT_ENDPOINT);
3737

3838
if (selfHosted) {
39-
const selfHostedAnswers = await inquirer.prompt(questionGetEndpoint);
39+
const selfHostedAnswers = endpoint ? { endpoint } : await inquirer.prompt(questionGetEndpoint);
4040

4141
globalConfig.setEndpoint(selfHostedAnswers.endpoint);
4242
}
@@ -61,15 +61,15 @@ const loginCommand = async ({ selfHosted }) => {
6161
});
6262
} catch (error) {
6363
if (error.response === 'user_more_factors_required') {
64-
const { factor } = await inquirer.prompt(questionsListFactors);
64+
const { factor } = mfa ? { factor: mfa } : await inquirer.prompt(questionsListFactors);
6565

6666
const challenge = await accountCreateMfaChallenge({
6767
factor,
6868
parseOutput: false,
6969
sdk: client
7070
});
7171

72-
const { otp } = await inquirer.prompt(questionsMfaChallenge);
72+
const { otp } = code ? { otp: code } : await inquirer.prompt(questionsMfaChallenge);
7373

7474
await accountUpdateMfaChallenge({
7575
challengeId: challenge.$id,
@@ -135,6 +135,11 @@ const whoami = new Command("whoami")
135135
const login = new Command("login")
136136
.description(commandDescriptions['login'])
137137
.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`)
138143
.configureHelp({
139144
helpWidth: process.stdout.columns || 80
140145
})

0 commit comments

Comments
 (0)