From db925c8e9686f648053286d158105557f70a541b Mon Sep 17 00:00:00 2001 From: Luke Weaver Date: Fri, 29 May 2026 12:27:48 -0400 Subject: [PATCH 1/9] Create create-users script and remove email and student information from Profile --- README.md | 11 +- scripts/create-users.mjs | 91 +++++++++++ scripts/username-words.json | 226 ++++++++++++++++++++++++++++ src/blog-posts | 2 +- src/components/profile/UserInfo.tsx | 70 ++++----- src/index.tsx | 5 - src/public-problems | 2 +- src/routes/Account.tsx | 10 +- src/routes/Login.tsx | 15 +- src/routes/Register.tsx | 104 ------------- 10 files changed, 370 insertions(+), 166 deletions(-) create mode 100644 scripts/create-users.mjs create mode 100644 scripts/username-words.json delete mode 100644 src/routes/Register.tsx diff --git a/README.md b/README.md index 3e296b68..ca1468bc 100644 --- a/README.md +++ b/README.md @@ -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 ` +- 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 diff --git a/scripts/create-users.mjs b/scripts/create-users.mjs new file mode 100644 index 00000000..b01f2c9a --- /dev/null +++ b/scripts/create-users.mjs @@ -0,0 +1,91 @@ +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")); + +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}`; +} + +async function createUser(username, password) { + 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 "); + 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 = generateAdjAnimalCombo() + Math.floor(Math.random() * 1000); + const password = generateAdjAnimalCombo(); + const ok = await createUser(username, password); + if (true) { + console.log(`User: ${username}\nPass: ${password}\n`); + successCount++; + } + } + console.log(`Done. ${successCount}/${count} users created successfully.`); +} + +main(); diff --git a/scripts/username-words.json b/scripts/username-words.json new file mode 100644 index 00000000..ffca7061 --- /dev/null +++ b/scripts/username-words.json @@ -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" + ] +} \ No newline at end of file diff --git a/src/blog-posts b/src/blog-posts index 6d501407..2f2a0027 160000 --- a/src/blog-posts +++ b/src/blog-posts @@ -1 +1 @@ -Subproject commit 6d501407062fcc74adfbb59ddf902b1ded259fe9 +Subproject commit 2f2a002748fed6eee9521e45818f264e8ceee027 diff --git a/src/components/profile/UserInfo.tsx b/src/components/profile/UserInfo.tsx index 0dd89ef6..99bc1660 100644 --- a/src/components/profile/UserInfo.tsx +++ b/src/components/profile/UserInfo.tsx @@ -1,7 +1,7 @@ import { Session } from "@supabase/supabase-js"; import { FormEvent, useEffect, useState } from "react"; import { supabase } from "../../supabaseClient"; -import { Button, FormLabel, Input, Stack, Typography } from "@mui/joy"; +import { Button, Stack, Typography } from "@mui/joy"; import { useOutletContext } from "react-router-dom"; import ProfileAvatar from "./ProfileAvatar"; @@ -16,8 +16,6 @@ export const ALL_PFPS = [ export default function UserInfo({ refetchProfile }: { refetchProfile: Function }) { const [isUpdating, setIsUpdating] = useState(false); - const [name, setName] = useState(""); - const [id, setId] = useState(""); const [loading, setLoading] = useState(false); const [error, setError] = useState(""); const [success, setSuccess] = useState(""); @@ -41,17 +39,15 @@ export default function UserInfo({ refetchProfile }: { refetchProfile: Function const { data, error } = await supabase .from('profiles') - .select('username, student_id, pfp_id') + .select('username, pfp_id') .eq('profile_id', user.id) .single(); if (!ignore) { if (error) { - alert(error.message); + setError(error.message); console.warn(error); } else if (data) { - setName(data.username ?? "Unnamed User"); - setId(data.student_id ?? ""); setPfpFileName(ALL_PFPS[data.pfp_id] ?? 0); setPfpArrPos(data.pfp_id ?? 0); } @@ -79,8 +75,6 @@ export default function UserInfo({ refetchProfile }: { refetchProfile: Function const updates = { profile_id: user.id, - username: name, - student_id: id, updated_at: new Date(), pfp_id: pfpArrPos }; @@ -115,32 +109,25 @@ export default function UserInfo({ refetchProfile }: { refetchProfile: Function isUpdating ?
- Edit Profile - Profile Picture - - - - + + + + - Name - setName(e.target.value)} - /> - Student ID - setId(e.target.value)} - /> - + {success} } diff --git a/src/index.tsx b/src/index.tsx index d17c07ee..edfd0269 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -13,7 +13,6 @@ import ErrorPage from './error'; import { theme } from './theme'; import Login from './routes/Login'; -import Register from './routes/Register'; import AccountWrapper from './routes/AccountWrapper'; import MainTutorial from './components/MainTutorial'; import PreSessionForm from './components/PreSessionForm'; @@ -71,10 +70,6 @@ const router = createHashRouter([ path: "change-password-req", element: }, - { - path: "register", - element: - }, { path: "profile", element: diff --git a/src/public-problems b/src/public-problems index d2b622f8..460fdd1e 160000 --- a/src/public-problems +++ b/src/public-problems @@ -1 +1 @@ -Subproject commit d2b622f82b2dbe75a8f42a526d1f9092b6e8d3b5 +Subproject commit 460fdd1e8bc17dd118ad5be93a99fc1a2ceddade diff --git a/src/routes/Account.tsx b/src/routes/Account.tsx index 152db040..7ea4c6c9 100644 --- a/src/routes/Account.tsx +++ b/src/routes/Account.tsx @@ -39,16 +39,20 @@ export default function Account({ session }: { session: Session }) { - - + + Profile Picture + + + Contract + - diff --git a/src/routes/Login.tsx b/src/routes/Login.tsx index 1a63f25d..1357eb9e 100644 --- a/src/routes/Login.tsx +++ b/src/routes/Login.tsx @@ -9,9 +9,8 @@ import { Session } from '@supabase/supabase-js'; */ export default function Login() { const [loading, setLoading] = useState(false); - const [email, setEmail] = useState(""); + const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); - const [error, setError] = useState(""); const [success, setSuccess] = useState(""); const { session } = useOutletContext<{ session: Session | null }>(); @@ -19,7 +18,7 @@ export default function Login() { // Clear data on unmount so it doesn't stay in memory useEffect(() => { return () => { - setEmail(""); + setUsername(""); setPassword(""); }; }, []); @@ -35,7 +34,7 @@ export default function Login() { setLoading(true); const { error } = await supabase.auth.signInWithPassword({ - email: email, + email: `${username}@coding-cat.internal`, password: password }); @@ -56,11 +55,11 @@ export default function Login() { Email setEmail(e.target.value)} + onChange={(e) => setUsername(e.target.value)} /> Password (); - - // Clear data on unmount so it doesn't stay in memory - useEffect(() => { - return () => { - setEmail(""); - setPassword(""); - }; - }, []); - - if (session) { - return - } - - const handleRegister = async (event: FormEvent) => { - event.preventDefault(); - setError(""); - setSuccess(""); - setLoading(true); - - const { data: signUpData, error: signUpError } = await supabase.auth.signUp({ - email: email, - password: password, - options: { - // !! if this is edited, it needs to match with the Supabase redirect URLs !! - // check 'Authentication/URL Configuration' - // ${window.location.origin} sets it dynamically to localhost or coding-cat.club - emailRedirectTo: `${window.location.origin}/#/auth/callback`, - }, - }); - - if(signUpError){ - setError(signUpError.message); - } - - if(signUpData.user){ - const { error: createProfileError } = await supabase - .from('profiles') - .insert({ - created_at: signUpData.user.created_at, - profile_id: signUpData.user.id - }); - if(createProfileError){ - setError(createProfileError.message); - }else{ - setSuccess('User Registered!'); - } - }else{ - setError("Something went wrong registering..."); - } - - setLoading(false); - } - - return ( - - Register -
- - Email - setEmail(e.target.value)} - /> - Password - setPassword(e.target.value)} - /> - - -
- { !!error && {error} } - { !!success && {success} } -
- ) -} From 98109d38b626f0d2b48c8a82cecebb58acb65c83 Mon Sep 17 00:00:00 2001 From: Luke Weaver Date: Fri, 29 May 2026 12:30:43 -0400 Subject: [PATCH 2/9] Add note about case-sensitivity in create-users --- scripts/create-users.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/create-users.mjs b/scripts/create-users.mjs index b01f2c9a..f31299a0 100644 --- a/scripts/create-users.mjs +++ b/scripts/create-users.mjs @@ -86,6 +86,7 @@ async function main() { } } console.log(`Done. ${successCount}/${count} users created successfully.`); + console.log("Note: usernames are not case-sensitive, passwords are") } main(); From 6ce0d3aa989a8d506c7300731d2ea625fc472aa6 Mon Sep 17 00:00:00 2001 From: Luke Weaver Date: Fri, 29 May 2026 12:46:51 -0400 Subject: [PATCH 3/9] Fix profile userInfo sections being misplaced --- src/index.css | 1 + src/routes/Account.tsx | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/index.css b/src/index.css index 1914d4fa..f0aa919d 100644 --- a/src/index.css +++ b/src/index.css @@ -225,6 +225,7 @@ textarea{ padding: 20px; margin: 10px 40px 30px; flex-direction: row; + align-self: center; border-radius: 10px; } diff --git a/src/routes/Account.tsx b/src/routes/Account.tsx index 8612e568..cd0a9c5f 100644 --- a/src/routes/Account.tsx +++ b/src/routes/Account.tsx @@ -36,12 +36,18 @@ export default function Account({ session }: { session: Session }) { } = useActivityTracker(user); return ( - + From 81f01c463a11fc2aff8c8690ba6d73efb8793e71 Mon Sep 17 00:00:00 2001 From: Luke Weaver Date: Fri, 29 May 2026 12:55:23 -0400 Subject: [PATCH 4/9] Remove password change auth flows --- src/index.tsx | 10 ------ src/routes/Account.tsx | 1 - src/routes/ChangePassword.tsx | 55 ----------------------------- src/routes/Login.tsx | 5 +-- src/routes/ReqPasswordChange.tsx | 59 -------------------------------- 5 files changed, 1 insertion(+), 129 deletions(-) delete mode 100644 src/routes/ChangePassword.tsx delete mode 100644 src/routes/ReqPasswordChange.tsx diff --git a/src/index.tsx b/src/index.tsx index edfd0269..33015e4e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -19,8 +19,6 @@ import PreSessionForm from './components/PreSessionForm'; import PostSessionForm from './components/PostSessionForm'; import AdminWrapper, { adminLoader } from './routes/AdminWrapper'; import AdminPage from './routes/AdminPage'; -import ChangePassword from './routes/ChangePassword'; -import ReqPasswordChange from './routes/ReqPasswordChange'; import AuthCallback from './routes/AuthCallback'; import Auth from './routes/Auth'; import BlogPostView, { blogPostLoader } from './routes/BlogPostView'; @@ -66,10 +64,6 @@ const router = createHashRouter([ path: "signin", element: }, - { - path: "change-password-req", - element: - }, { path: "profile", element: @@ -94,10 +88,6 @@ const router = createHashRouter([ { path: "callback", element: - }, - { - path: "change-password", - element: } ] } diff --git a/src/routes/Account.tsx b/src/routes/Account.tsx index cd0a9c5f..5ce97aff 100644 --- a/src/routes/Account.tsx +++ b/src/routes/Account.tsx @@ -52,7 +52,6 @@ export default function Account({ session }: { session: Session }) { className="account-wrapper" > - Profile Picture diff --git a/src/routes/ChangePassword.tsx b/src/routes/ChangePassword.tsx deleted file mode 100644 index 408234d9..00000000 --- a/src/routes/ChangePassword.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import { FormEvent, useState } from 'react' -import { supabase } from '../supabaseClient' -import { Box, Button, FormLabel, Input, Stack, Typography } from '@mui/joy'; -import { Navigate } from 'react-router-dom'; - -/** - * Change Password page for the app. - */ -export default function ChangePassword() { - const [done, setDone] = useState(false); - const [loading, setLoading] = useState(false); - const [newPassword, setNewPassword] = useState(""); - const [error, setError] = useState(""); - - const handleSubmit = async (event: FormEvent) => { - event.preventDefault(); - setError(""); - setLoading(true); - - const { error } = await supabase.auth.updateUser({ password: newPassword }); - - if (error) { - setError(error.message); - } else { - await supabase.auth.signOut(); - setDone(true); - } - setLoading(false); - } - - if (done) return ; - - return ( - - Change Password -
- - New Password - setNewPassword(e.target.value)} - /> - - -
- {!!error && {error}} -
- ) -} diff --git a/src/routes/Login.tsx b/src/routes/Login.tsx index 1357eb9e..9872e612 100644 --- a/src/routes/Login.tsx +++ b/src/routes/Login.tsx @@ -1,7 +1,7 @@ import { FormEvent, useEffect, useState } from 'react' import { supabase } from '../supabaseClient' import { Box, Button, FormLabel, Input, Stack, Typography } from '@mui/joy'; -import { Link, Navigate, useOutletContext } from 'react-router-dom'; +import { Navigate, useOutletContext } from 'react-router-dom'; import { Session } from '@supabase/supabase-js'; /** @@ -75,9 +75,6 @@ export default function Login() { {loading ? Loading : Login} - - - { !!error && {error} } { !!success && {success} }
diff --git a/src/routes/ReqPasswordChange.tsx b/src/routes/ReqPasswordChange.tsx deleted file mode 100644 index 85013da8..00000000 --- a/src/routes/ReqPasswordChange.tsx +++ /dev/null @@ -1,59 +0,0 @@ -import { FormEvent, useState } from 'react' -import { supabase } from '../supabaseClient' -import { Box, Button, FormLabel, Input, Stack, Typography } from '@mui/joy'; - -/** - * Request Password Change page for the app. - */ -export default function ReqPasswordChange() { - const [loading, setLoading] = useState(false); - const [email, setEmail] = useState(""); - const [error, setError] = useState(""); - const [success, setSuccess] = useState(""); - - const handleSubmit = async (event: FormEvent) => { - event.preventDefault(); - setError(""); - setSuccess(""); - setLoading(true); - - const { error } = await supabase.auth.resetPasswordForEmail(email, { - // !! if this is edited, it needs to match with the Supabase redirect URLs !! - // check 'Authentication/URL Configuration - // ${window.location.origin} sets it dynamically to localhost or coding-cat.club - redirectTo: `${window.location.origin}/` - }); - - if(error){ - setError(error.message) - }else { - setSuccess("Check your email for a password reset link!") - } - - setLoading(false); - } - - return ( - - Reset Password -
- - Email - setEmail(e.target.value)} - /> - - -
- { !!error && {error} } - { !!success && {success} } -
- ) -} From 20dea56815b6652f7ba69c7e9226800ad962b877 Mon Sep 17 00:00:00 2001 From: Luke Weaver Date: Fri, 29 May 2026 13:06:38 -0400 Subject: [PATCH 5/9] Update blog posts --- src/blog-posts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blog-posts b/src/blog-posts index 2f2a0027..dc309803 160000 --- a/src/blog-posts +++ b/src/blog-posts @@ -1 +1 @@ -Subproject commit 2f2a002748fed6eee9521e45818f264e8ceee027 +Subproject commit dc309803d0d193d2c97f15b6ddc69f9c672fb7cd From 97b454c50ffe7100bd3c7279f45907de0d215377 Mon Sep 17 00:00:00 2001 From: Luke Weaver Date: Fri, 29 May 2026 13:13:36 -0400 Subject: [PATCH 6/9] Add check for @ to allow old emails to continue to work --- src/routes/Login.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/routes/Login.tsx b/src/routes/Login.tsx index 9872e612..e9db84f9 100644 --- a/src/routes/Login.tsx +++ b/src/routes/Login.tsx @@ -33,10 +33,15 @@ export default function Login() { setSuccess(""); setLoading(true); - const { error } = await supabase.auth.signInWithPassword({ - email: `${username}@coding-cat.internal`, - password: password - }); + const { error } = username.includes("@") + ? await supabase.auth.signInWithPassword({ + email: username, + password: password + }) + : await supabase.auth.signInWithPassword({ + email: `${username}@coding-cat.internal`, + password: password + }); if (error) { setError(error.message); From 46a7153268f28de31122d0241fb50da3c7dc41a0 Mon Sep 17 00:00:00 2001 From: Luke Weaver Date: Fri, 29 May 2026 14:23:03 -0400 Subject: [PATCH 7/9] Remove lingering Register button from UpperNavBar --- src/components/layout/UpperNavBar.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/components/layout/UpperNavBar.tsx b/src/components/layout/UpperNavBar.tsx index bf3522c9..45645719 100644 --- a/src/components/layout/UpperNavBar.tsx +++ b/src/components/layout/UpperNavBar.tsx @@ -104,9 +104,6 @@ export default function UpperNavBar({ - - - )} From 03440f6df964b3cb6d77f98a55c37634aaae8020 Mon Sep 17 00:00:00 2001 From: Luke Weaver Date: Fri, 29 May 2026 14:36:12 -0400 Subject: [PATCH 8/9] Implement forced username uniqueness within the same run. Fix DB not actually using ok --- scripts/{create-users.mjs => create-users.ts} | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) rename scripts/{create-users.mjs => create-users.ts} (86%) diff --git a/scripts/create-users.mjs b/scripts/create-users.ts similarity index 86% rename from scripts/create-users.mjs rename to scripts/create-users.ts index f31299a0..0a051db3 100644 --- a/scripts/create-users.mjs +++ b/scripts/create-users.ts @@ -22,6 +22,7 @@ const supabase = createClient(SUPABASE_URL, SERVICE_ROLE_KEY, { }); const usernameParts = JSON.parse(readFileSync(join(__dirname, "./username-words.json"), "utf-8")); +const usedUsernames: string[] = []; function generateAdjAnimalCombo() { const adjective = usernameParts.adjectives[ @@ -34,7 +35,18 @@ function generateAdjAnimalCombo() { return `${adjective}${animal}`; } -async function createUser(username, password) { +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({ @@ -77,10 +89,10 @@ async function main() { let successCount = 0; for (let i = 0; i < count; i++) { - const username = generateAdjAnimalCombo() + Math.floor(Math.random() * 1000); + const username = generateUniqueUsername(); const password = generateAdjAnimalCombo(); const ok = await createUser(username, password); - if (true) { + if (ok) { console.log(`User: ${username}\nPass: ${password}\n`); successCount++; } From 49795f731df5cfe2c2d171552823a0191963513e Mon Sep 17 00:00:00 2001 From: Luke Weaver Date: Fri, 29 May 2026 14:50:12 -0400 Subject: [PATCH 9/9] Move UserData type to types.ts Add userData to context. Display username in profile --- src/components/profile/UserInfo.tsx | 4 +++- src/hooks/useAuth.ts | 6 +----- src/routes/Account.tsx | 4 +++- src/routes/root.tsx | 2 +- src/types.ts | 5 +++++ 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/components/profile/UserInfo.tsx b/src/components/profile/UserInfo.tsx index 99bc1660..1e00d832 100644 --- a/src/components/profile/UserInfo.tsx +++ b/src/components/profile/UserInfo.tsx @@ -4,6 +4,7 @@ import { supabase } from "../../supabaseClient"; import { Button, Stack, Typography } from "@mui/joy"; import { useOutletContext } from "react-router-dom"; import ProfileAvatar from "./ProfileAvatar"; +import { UserData } from "../../types"; // TODO: maybe get these dynamically? export const ALL_PFPS = [ @@ -14,7 +15,7 @@ export const ALL_PFPS = [ "thumbs-up-pfp.png" ] -export default function UserInfo({ refetchProfile }: { refetchProfile: Function }) { +export default function UserInfo({ userData, refetchProfile }: { userData: UserData | null, refetchProfile: Function }) { const [isUpdating, setIsUpdating] = useState(false); const [loading, setLoading] = useState(false); const [error, setError] = useState(""); @@ -145,6 +146,7 @@ export default function UserInfo({ refetchProfile }: { refetchProfile: Function height={pfpHeight} width={pfpWidth} /> + { userData?.name && {userData.name} } diff --git a/src/hooks/useAuth.ts b/src/hooks/useAuth.ts index a8a9ddf4..67b34908 100644 --- a/src/hooks/useAuth.ts +++ b/src/hooks/useAuth.ts @@ -1,11 +1,7 @@ import { useState, useEffect, useCallback } from 'react'; import { supabase } from '../supabaseClient'; import { type Session } from '@supabase/supabase-js'; - -interface UserData { - name: string; - pfp_id: number; -} +import { UserData } from '../types'; interface UseAuthReturn { session: Session | null; diff --git a/src/routes/Account.tsx b/src/routes/Account.tsx index 5ce97aff..f6d00ce8 100644 --- a/src/routes/Account.tsx +++ b/src/routes/Account.tsx @@ -11,6 +11,7 @@ import OtherStats from "../components/profile/progress/other-stats/OtherStats"; import { useOutletContext } from "react-router-dom"; import SessionReflections from "../components/profile/sessions/SessionReflections"; import useActivityTracker from "../hooks/useActivityTracker"; +import { UserData } from "../types"; /** * The `Account` component handles everything related to the profile page. @@ -18,6 +19,7 @@ import useActivityTracker from "../hooks/useActivityTracker"; */ export default function Account({ session }: { session: Session }) { const { refetchProfile } = useOutletContext<{ refetchProfile: () => Promise }>(); + const { userData } = useOutletContext<{ userData: UserData | null }>(); // Change "reflections" into something else const [view, setView] = useState<"reflections" | "activity" | "sessions">("reflections"); @@ -52,7 +54,7 @@ export default function Account({ session }: { session: Session }) { className="account-wrapper" > - + Contract diff --git a/src/routes/root.tsx b/src/routes/root.tsx index b2108036..7d96aff0 100644 --- a/src/routes/root.tsx +++ b/src/routes/root.tsx @@ -371,7 +371,7 @@ export default function App() { setActiveProblem, session, isAdmin, refetchProgress: fetchProgress, refetchProfile: fetchProfile, activeSession, sessionId, sessionRemainingSeconds, sessionDuration, plannedExerciseCount, problemSessionStats, setProblemSessionStats, - progress, sessionTimerRunning, + progress, sessionTimerRunning, userData }} /> diff --git a/src/types.ts b/src/types.ts index 5bf7751d..0164fbe0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -229,4 +229,9 @@ export interface SessionReflectionRecord { exercise_goals: number; pre_session_reflection: FormAnswers | null; post_session_reflection: FormAnswers | null; +} + +export interface UserData { + name: string; + pfp_id: number; } \ No newline at end of file