Skip to content
Merged
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@ Once the program is finished:
- Please, for Eric's sake, make sure you didn't break anything

*Note: This program was primarily made with the intention of making "coding" and "haystack"-type problems.*
*If you make mutation problems, the finished problem directory will be placed correctly, **but will be missing the mutation.py files***
*If you make mutation problems, the finished problem directory will be placed correctly,* **but will be missing the mutation.py files**


### Create New Users

- To create new users, 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 <numberOfUsers>`
- 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**


### Modify Contract
Expand Down
104 changes: 104 additions & 0 deletions scripts/create-users.ts
Comment thread
guitarwhal marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { createClient } from "@supabase/supabase-js";
import { readFileSync } from "fs";
import { config } from "dotenv";import { createRequire } from "module";
import { fileURLToPath } from "url";
import { dirname, join } from "path";

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

const usernameParts = JSON.parse(readFileSync(join(__dirname, "./username-words.json"), "utf-8"));
const usedUsernames: string[] = [];

function generateAdjAnimalCombo() {
const adjective = usernameParts.adjectives[
Math.floor(Math.random() * usernameParts.adjectives.length)
];
const animal = usernameParts.animals[
Math.floor(Math.random() * usernameParts.animals.length)
];

return `${adjective}${animal}`;
}

function generateUniqueUsername() {
let username;

do{
username = generateAdjAnimalCombo() + Math.floor(Math.random() * 1000);
}while(usedUsernames.includes(username));
usedUsernames.push(username);

return username;
}

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;
}

async function main() {
const count = parseInt(process.argv[2]);
if (!count || isNaN(count) || count < 1) {
console.error("Usage: node create-users.mjs <number_of_users>");
console.error("Example: node create-users.mjs 10");
process.exit(1);
}

console.log(`\nCreating ${count} users...\n`);

let successCount = 0;

for (let i = 0; i < count; i++) {
const username = generateUniqueUsername();
const password = generateAdjAnimalCombo();
const ok = await createUser(username, password);
if (ok) {
console.log(`User: ${username}\nPass: ${password}\n`);
successCount++;
}
}
console.log(`Done. ${successCount}/${count} users created successfully.`);
console.log("Note: usernames are not case-sensitive, passwords are")
}

main();
226 changes: 226 additions & 0 deletions scripts/username-words.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
{
"adjectives": [
"Agile",
"Amber",
"Ancient",
"Arctic",
"Ashen",
"Astral",
"Autumn",
"Azure",
"Bamboo",
"Blazing",
"Bold",
"Brave",
"Breezy",
"Bright",
"Bronze",
"Calm",
"Candid",
"Celestial",
"Clever",
"Cloudy",
"Cobalt",
"Coding",
"Cosmic",
"Crimson",
"Crystal",
"Curious",
"Dancing",
"Daring",
"Dawn",
"Desert",
"Distant",
"Divine",
"Dreamy",
"Dusky",
"Dynamic",
"Echoing",
"Electric",
"Elegant",
"Emerald",
"Epic",
"Fabled",
"Feral",
"Fiery",
"Flying",
"Forest",
"Frozen",
"Gentle",
"Ghostly",
"Glacial",
"Golden",
"Grand",
"Hidden",
"Hollow",
"Icy",
"Iron",
"Ivory",
"Jade",
"Jolly",
"Jovial",
"Lively",
"Lunar",
"Majestic",
"Mellow",
"Midnight",
"Mighty",
"Misty",
"Moonlit",
"Mystic",
"Nimble",
"Noble",
"Nova",
"Obsidian",
"Ocean",
"Phantom",
"Plucky",
"Polar",
"Prairie",
"Primal",
"Quick",
"Quiet",
"Radiant",
"Rapid",
"Ravenous",
"Regal",
"River",
"Roaming",
"Royal",
"Rustic",
"Savage",
"Scarlet",
"Shadow",
"Shimmering",
"Silent",
"Silver",
"Skybound",
"Solar",
"Stormy",
"Swift",
"Thunder",
"Timber",
"Twilight",
"Velvet",
"Verdant",
"Vibrant",
"Violet",
"Wandering",
"Whispering",
"Wild",
"Winter",
"Wise",
"Zealous"
],
"animals": [
"Aardvark",
"Albatross",
"Alligator",
"Alpaca",
"Antelope",
"Armadillo",
"Badger",
"Barracuda",
"Bat",
"Bear",
"Beaver",
"Bison",
"Boar",
"Buffalo",
"Butterfly",
"Camel",
"Capybara",
"Caribou",
"Cassowary",
"Cat",
"Cheetah",
"Cobra",
"Condor",
"Cougar",
"Coyote",
"Crab",
"Crane",
"Crocodile",
"Crow",
"Deer",
"Dingo",
"Dolphin",
"Dragonfly",
"Duck",
"Eagle",
"Echidna",
"Falcon",
"Ferret",
"Firefly",
"Fox",
"Frog",
"Gazelle",
"Gecko",
"Giraffe",
"Goose",
"Gorilla",
"Hawk",
"Hedgehog",
"Heron",
"Hippo",
"Horse",
"Hummingbird",
"Hyena",
"Ibex",
"Iguana",
"Jackal",
"Jaguar",
"Jellyfish",
"Kangaroo",
"Kingfisher",
"Koala",
"Kraken",
"Lemur",
"Leopard",
"Lion",
"Llama",
"Lobster",
"Lynx",
"Mammoth",
"Manatee",
"Meerkat",
"Moose",
"Narwhal",
"Newt",
"Octopus",
"Opossum",
"Orca",
"Otter",
"Owl",
"Panther",
"Parrot",
"Peacock",
"Penguin",
"Phoenix",
"Puma",
"Python",
"Rabbit",
"Raccoon",
"Raven",
"Rhino",
"Salamander",
"Scorpion",
"Seahorse",
"Seal",
"Shark",
"Sloth",
"Sparrow",
"Spider",
"Squid",
"Swan",
"Tabby",
"Tiger",
"Toucan",
"Turtle",
"Viper",
"Walrus",
"Wolf",
"Yak",
"Zebra"
]
}
3 changes: 0 additions & 3 deletions src/components/layout/UpperNavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ export default function UpperNavBar({
<Link to="/signin">
<Button>Login</Button>
</Link>
<Link to="/register">
<Button>Register</Button>
</Link>
</>
)}
</Box>
Expand Down
Loading
Loading