From 01b69a4643573cd09be715d2575c7290f6bf8e17 Mon Sep 17 00:00:00 2001 From: Luke Weaver Date: Mon, 1 Jun 2026 11:22:12 -0400 Subject: [PATCH 1/3] Create create-custom-user.ts and remove unused import in create-users.ts --- scripts/create-custom-user.ts | 94 +++++++++++++++++++++++++++++++++++ scripts/create-users.ts | 2 +- 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 scripts/create-custom-user.ts diff --git a/scripts/create-custom-user.ts b/scripts/create-custom-user.ts new file mode 100644 index 0000000..4c7b327 --- /dev/null +++ b/scripts/create-custom-user.ts @@ -0,0 +1,94 @@ +import { createClient } from "@supabase/supabase-js"; +import { config } from "dotenv"; +import { fileURLToPath } from "url"; +import { dirname, join } from "path"; +import * as readline from 'readline'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); +config({ path: join(__dirname, "../.env.local") }); + +const SUPABASE_URL = process.env.REACT_APP_SUPABASE_URL; +const SERVICE_ROLE_KEY = process.env.SUPABASE_SERVICE_ROLE_KEY; +// not a real domain, just to comply with Supabase email field +const EMAIL_DOMAIN = "coding-cat.internal"; + +if (!SUPABASE_URL || !SERVICE_ROLE_KEY) { + console.error("Missing REACT_APP_SUPABASE_URL or SUPABASE_SERVICE_ROLE_KEY in .env"); + process.exit(1); +} + +const supabase = createClient(SUPABASE_URL, SERVICE_ROLE_KEY, { + auth: { autoRefreshToken: false, persistSession: false } +}); + +async function createUser(username: string, password: string) { + const email = `${username}@${EMAIL_DOMAIN}`; + + const { data, error } = await supabase.auth.admin.createUser({ + email, + password, + email_confirm: true, + }); + + if (error) { + console.error(`Auth error for "${username}": ${error.message}`); + return false; + } + + const { error: profileError } = await supabase + .from("profiles") + .upsert({ + profile_id: data.user.id, + username: username, + created_at: data.user.created_at, + }, { onConflict: "profile_id" }); + + if (profileError) { + console.error(`Profile error for "${username}": ${profileError.message}`); + return false; + } + + return true; +} + +/** + * @param input the input to be validated + * @returns boolean whether the input is alphanumerical + */ +function validateInput(input: string){ + const regex = /^[a-zA-Z0-9]+$/; + return regex.test(input); +} + +function getInput(question: string): Promise{ + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout + }); + + return new Promise((resolve) => { + rl.question(question, (answer: string) => { + rl.close(); + resolve(answer); + }); + }); +} + +async function main() { + let username; + let password; + let valid; + + do{ + username = await getInput("Enter username (only alphanumerical characters): "); + password = await getInput("Enter password: "); + + valid = validateInput(username) && validateInput(password); + if(!valid) console.log("Invalid input. Only alphanumerical characters are allowed."); + }while(!valid); + + const dbOk = await createUser(username, password); + if(dbOk) console.log(`Successfully created user ${username}!`) +} + +main(); diff --git a/scripts/create-users.ts b/scripts/create-users.ts index 0a051db..e93cac4 100644 --- a/scripts/create-users.ts +++ b/scripts/create-users.ts @@ -1,6 +1,6 @@ import { createClient } from "@supabase/supabase-js"; import { readFileSync } from "fs"; -import { config } from "dotenv";import { createRequire } from "module"; +import { config } from "dotenv"; import { fileURLToPath } from "url"; import { dirname, join } from "path"; From ce93117bce7b459076be4d4a52cab7404c5d2623 Mon Sep 17 00:00:00 2001 From: Luke Weaver Date: Tue, 2 Jun 2026 15:21:57 -0400 Subject: [PATCH 2/3] Update README --- README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ca1468b..efc6c5c 100644 --- a/README.md +++ b/README.md @@ -69,11 +69,20 @@ Once the program is finished: ### Create New Users -- To create new users, ensure you have a service role key in your .env as `SUPABASE_SERVICE_ROLE_KEY` +- Regardless of whether you're creating a new batch of users, or a single custom one ensure you have a service role key in your .env as `SUPABASE_SERVICE_ROLE_KEY` - This can be found right under the Anon key, see "Run Locally" above **THE VALUE IS SECRET, DO NOT SHARE** -- Run `node scripts/create-users.mjs ` + +#### Batch Creation + +- Run `node scripts/create-users.ts ` - The script will print out the new users login credentials -*Note: As the app no longer uses emails, resetting a password would need to be done manually in SQL.* **Please ask users to be careful and not lose their creds** +*Note: As the app no longer uses emails, resetting a password would need to be done manually in SQL.* **Please ask new users to be careful and not lose their creds** + +#### Custom Creation + +- Run `node scripts/create-custom-user.ts` +- Follow the script instructions to create a user with a custom username and password +*Note: As the app used to use emails as usernames, all new users are internally referred to as `@coding-cat.internal`, but all previous email accounts will still work.* ### Modify Contract From 0de7882b75cd414fb1c86f9d4a9e29f6056dfe83 Mon Sep 17 00:00:00 2001 From: Luke Weaver Date: Tue, 2 Jun 2026 15:24:59 -0400 Subject: [PATCH 3/3] Update README --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index efc6c5c..3b0a019 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,10 @@ Once the program is finished: #### Batch Creation - Run `node scripts/create-users.ts ` -- The script will print out the new users login credentials +- The script will print out the new users login credentials and create all the corresponding users in the DB +- Credentials are formatted as such (both are capitalized, but only password is case-sensitive): + - Username: `<1-999>` + - Password: `` *Note: As the app no longer uses emails, resetting a password would need to be done manually in SQL.* **Please ask new users to be careful and not lose their creds** #### Custom Creation