From 83571c0f044b20b99d1cfbd3eeb061d0eb24baed Mon Sep 17 00:00:00 2001 From: Tiffany Chang Date: Sat, 7 Mar 2026 01:01:42 -0800 Subject: [PATCH 1/2] Sign up form fixes - added username and adds as display name in supabase auth table - fixed weak password message to be more descriptive --- client/src/Login.tsx | 5 +++-- client/src/SignUpForm.tsx | 13 +++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/client/src/Login.tsx b/client/src/Login.tsx index f2c8ed1..d4395af 100644 --- a/client/src/Login.tsx +++ b/client/src/Login.tsx @@ -43,7 +43,7 @@ const Login = () => { } }; - const handleSignUp = async (email: string, password: string, name?: string) => { + const handleSignUp = async (email: string, password: string, username: string) => { setError(null); setIsLoading(true); @@ -53,6 +53,7 @@ const Login = () => { email: email, password: password, options: { + data: {display_name: username}, emailRedirectTo: "http://localhost:5173/" } }); @@ -61,7 +62,7 @@ const Login = () => { if (error.code === 'user_already_exists') { setError('An account with this email already exists. Please sign in instead.'); } else if (error.code ===('weak_password')) { - setError('Password is too weak. Please use a strong password.'); + setError('Password is too weak. Please use a password of at least 6 characters.'); } else { setError(error.message); } diff --git a/client/src/SignUpForm.tsx b/client/src/SignUpForm.tsx index 8d453ff..5a10a6b 100644 --- a/client/src/SignUpForm.tsx +++ b/client/src/SignUpForm.tsx @@ -2,17 +2,18 @@ import { createClient } from './supabase.ts'; import { useState } from 'react'; interface SignUpProps { - onSubmit: (email: string, password: string) => Promise; + onSubmit: (email: string, password: string, username: string) => Promise; isLoading?: boolean; } export default function SignUpForm({ onSubmit, isLoading = false }: SignUpProps) { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); + const [username, setUsername] = useState(''); const [error, setError] = useState(''); const handleSubmit = async (e: React.SubmitEvent) => { e.preventDefault(); - await onSubmit(email, password); + await onSubmit(email, password, username); }; @@ -26,6 +27,14 @@ export default function SignUpForm({ onSubmit, isLoading = false }: SignUpProps) placeholder="Enter email" /> +
+ setUsername(e.target.value)} + placeholder="Enter username" + /> +
Date: Sat, 7 Mar 2026 01:19:20 -0800 Subject: [PATCH 2/2] frontend test updated for sign up --- client/src/Login.test.tsx | 5 +++-- client/src/SignUpForm.test.tsx | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/client/src/Login.test.tsx b/client/src/Login.test.tsx index 0e21834..c8213f5 100644 --- a/client/src/Login.test.tsx +++ b/client/src/Login.test.tsx @@ -47,7 +47,7 @@ describe('Login', () => { fireEvent.click(screen.getByRole('button', { name: 'Sign In' })); await waitFor(() => { - expect(mockSignIn).toHaveBeenCalledWith({ email: 'test@test.com', password: 'password123' }); + expect(mockSignIn).toHaveBeenCalledWith({ email: 'test@test.com', password: 'password123'}); }); }); @@ -85,6 +85,7 @@ describe('Login', () => { render(); fireEvent.click(screen.getByText('Sign Up')); fireEvent.change(screen.getByPlaceholderText('Enter email'), { target: { value: 'test@test.com' } }); + fireEvent.change(screen.getByPlaceholderText('Enter username'), { target: { value: 'test_user' } }); fireEvent.change(screen.getByPlaceholderText('Enter password'), { target: { value: 'password123' } }); fireEvent.click(screen.getByRole('button', { name: 'Sign Up' })); @@ -111,7 +112,7 @@ describe('Login', () => { fireEvent.click(screen.getByRole('button', { name: 'Sign Up' })); await waitFor(() => { - expect(screen.getByText('Password is too weak. Please use a strong password.')).toBeInTheDocument(); + expect(screen.getByText('Password is too weak. Please use a password of at least 6 characters.')).toBeInTheDocument(); }); }); diff --git a/client/src/SignUpForm.test.tsx b/client/src/SignUpForm.test.tsx index 2e943d3..ea72603 100644 --- a/client/src/SignUpForm.test.tsx +++ b/client/src/SignUpForm.test.tsx @@ -13,25 +13,29 @@ describe('SignUpForm', () => { it('renders without crashing', () => { render(); expect(screen.getByPlaceholderText('Enter email')).toBeInTheDocument(); + expect(screen.getByPlaceholderText('Enter username')).toBeInTheDocument(); expect(screen.getByPlaceholderText('Enter password')).toBeInTheDocument(); }); it('updates email and password fields', () => { render(); fireEvent.change(screen.getByPlaceholderText('Enter email'), { target: { value: 'test@test.com' } }); + fireEvent.change(screen.getByPlaceholderText('Enter username'), { target: { value: 'test_user' } }); fireEvent.change(screen.getByPlaceholderText('Enter password'), { target: { value: 'admin1' } }); expect(screen.getByPlaceholderText('Enter email')).toHaveValue('test@test.com'); + expect(screen.getByPlaceholderText('Enter username')).toHaveValue('test_user'); expect(screen.getByPlaceholderText('Enter password')).toHaveValue('admin1'); }); it('calls onSubmit with email and password when submitted', async () => { render(); fireEvent.change(screen.getByPlaceholderText('Enter email'), { target: { value: 'test@test.com' } }); + fireEvent.change(screen.getByPlaceholderText('Enter username'), { target: { value: 'test_user' } }); fireEvent.change(screen.getByPlaceholderText('Enter password'), { target: { value: 'admin1' } }); fireEvent.click(screen.getByText('Sign Up')); await waitFor(() => { - expect(mockOnSubmit).toHaveBeenCalledWith('test@test.com', 'admin1'); + expect(mockOnSubmit).toHaveBeenCalledWith('test@test.com', 'admin1', 'test_user'); }); }); });