Repository navigation
Anonymise users and add script for creating users #283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
db925c8
Create create-users script and remove email and student information f…
McDingus 98109d3
Add note about case-sensitivity in create-users
McDingus 4bf7c0d
Merge conflicts?
McDingus 6ce0d3a
Fix profile userInfo sections being misplaced
McDingus 81f01c4
Remove password change auth flows
McDingus 20dea56
Update blog posts
McDingus 97b454c
Add check for @ to allow old emails to continue to work
McDingus 46a7153
Remove lingering Register button from UpperNavBar
McDingus 03440f6
Implement forced username uniqueness within the same run. Fix DB not …
McDingus 49795f7
Move UserData type to types.ts Add userData to context. Display usern…
McDingus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.