Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

chore: Add more comments and user messages to create-user cmd

LaraClara60bcd7ae4926
diff --git a/config/create-user.js b/config/create-user.js
index c8f0ffcaf5..b9cb9c5cdf 100644
--- a/config/create-user.js
+++ b/config/create-user.js
@@ -10,21 +10,48 @@ const silentExit = (code = 0) => {
}
(async () => {
- console.orange('Warming up the engines...')
- await connectDb();
- await migrateDb();
- // Okay lets show the user some information about what we are doing
- console.purple('--------------------------')
- console.purple('Setup a new user account!')
+ /**
+ * Connect to the database
+ * - If it takes a while, we'll warn the user
+ */
+ // Warn the user if this is taking a while
+ let timeout = setTimeout(() => {
+ console.orange('This is taking a while... You may need to check your connection if this fails.');
+ timeout = setTimeout(() => {
+ console.orange('Still going... Might as well assume the connection failed...');
+ timeout = setTimeout(() => {
+ console.orange('Error incoming in 3... 2... 1...');
+ }, 13000);
+ }, 10000);
+ }, 5000);
+ // Attempt to connect to the database
+ try {
+ console.orange('Warming up the engines...')
+ await connectDb();
+ clearTimeout(timeout);
+ await migrateDb();
+ } catch (e) {
+ console.error(e);
+ silentExit(1);
+ }
+
+ /**
+ * Show the welcome / help menu
+ */
console.purple('--------------------------')
- console.orange('Usage: npm run create-user <email> <name> <username>')
- console.orange('Note: if you do not pass in the arguments, you will be prompted for them.')
- console.orange('If you really need to pass in the password, you can do so as the 4th argument (not recommended for security).')
+ console.purple('Create a new user account!')
console.purple('--------------------------')
+ // If we don't have enough arguments, show the help menu
+ if (process.argv.length < 5) {
+ console.orange('Usage: npm run create-user <email> <name> <username>')
+ console.orange('Note: if you do not pass in the arguments, you will be prompted for them.')
+ console.orange('If you really need to pass in the password, you can do so as the 4th argument (not recommended for security).')
+ console.purple('--------------------------')
+ }
- // These will be passed as arguments to the console
- // node config/create-user.js <name> <email> <username>
- // lets set them up as variables with some defaults
+ /**
+ * Set up the variables we need and get the arguments if they were passed in
+ */
let email = '';
let password = '';
let name = '';
@@ -42,6 +69,10 @@ const silentExit = (code = 0) => {
password = process.argv[5];
}
}
+
+ /**
+ * If we don't have the right number of arguments, lets prompt the user for them
+ */
if (!email) {
email = await askQuestion('Email:');
}
@@ -73,16 +104,17 @@ const silentExit = (code = 0) => {
}
}
-
- const user = { email, password, name, username, confirm_password: password };
- // Let's check if the email or username already exists
+ // Validate the user doesn't already exist
const userExists = await User.findOne({ $or: [{ email }, { username }] });
if (userExists) {
console.red('Error: A user with that email or username already exists!');
silentExit(1);
}
- // Now lets register the user
+ /**
+ * Now that we have all the variables we need, lets create the user
+ */
+ const user = { email, password, name, username, confirm_password: password };
let result;
try {
result = await registerUser(user);