@@ -6,19 +6,50 @@ const { globalConfig, localConfig } = require("../config");
6
6
const { actionRunner, success, parseBool, commandDescriptions, error, parse, log, drawTable } = require("../parser");
7
7
const ID = require("../id");
8
8
{% if sdk .test != " true" %}
9
- const { questionsLogin, questionLoginWithEndpoint, questionsLogout, questionsListFactors, questionsMfaChallenge } = require("../questions");
10
- const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account");
9
+ const { questionsRegister, questionsRegisterWithEndpoint, questionsLogin, questionLoginWithEndpoint, questionsLogout, questionsListFactors, questionsMfaChallenge } = require("../questions");
10
+ const { accountCreate, accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account");
11
11
12
12
const DEFAULT_ENDPOINT = 'https://cloud.appwrite.io/v1';
13
13
14
+ const registerCommand = async ({ selfHosted, email, password, endpoint, name }) => {
15
+ let answers;
16
+ let configEndpoint = DEFAULT_ENDPOINT;
17
+
18
+ if (selfHosted) {
19
+ answers = endpoint && email && password ? { endpoint, email, password } : await inquirer.prompt(questionsRegisterWithEndpoint);
20
+ configEndpoint = answers.endpoint;
21
+ } else {
22
+ answers = email && password ? { email, password } : await inquirer.prompt(questionsRegister);
23
+ }
24
+
25
+ globalConfig.setEndpoint(configEndpoint);
26
+
27
+ let client = await sdkForConsole(false);
28
+
29
+ try {
30
+ await accountCreate({
31
+ userId: ID.unique(),
32
+ email: answers.email,
33
+ password: answers.password,
34
+ parseOutput: false,
35
+ name: answers.name,
36
+ sdk: client,
37
+ })
38
+
39
+ success();
40
+ } catch (e) {
41
+ throw e;
42
+ }
43
+
44
+ }
14
45
const loginCommand = async ({ selfHosted, email, password, endpoint, mfa, code }) => {
15
46
const oldCurrent = globalConfig.getCurrentLogin();
16
47
let answers = {};
17
48
let configEndpoint = DEFAULT_ENDPOINT;
18
49
19
50
if (selfHosted) {
20
51
answers = endpoint && email && password ? { endpoint, email, password } : await inquirer.prompt(questionLoginWithEndpoint);
21
- configEndpoint = answers.endpoint;
52
+ configEndpoint = answers.endpoint;
22
53
} else {
23
54
answers = email && password ? { email, password } : await inquirer.prompt(questionsLogin);
24
55
}
@@ -148,6 +179,15 @@ const login = new Command("login")
148
179
})
149
180
.action(actionRunner(loginCommand));
150
181
182
+ const register = new Command("register")
183
+ .description(commandDescriptions['login'])
184
+ .option(`-sh, --self-hosted`, `Flag for enabling custom endpoint for self hosted instances`)
185
+ .option(`--name [name]`, `User name`)
186
+ .option(`--email [email]`, `User email`)
187
+ .option(`--password [password]`, `User password`)
188
+ .option(`--endpoint [endpoint]`, `Appwrite endpoint for self hosted instances`)
189
+ .action(actionRunner(registerCommand));
190
+
151
191
const singleLogout = async (accountId) => {
152
192
try {
153
193
let client = await sdkForConsole();
@@ -308,6 +348,7 @@ module.exports = {
308
348
loginCommand,
309
349
whoami,
310
350
login,
351
+ register,
311
352
logout,
312
353
{% endif %}
313
354
migrate,
0 commit comments