Problem: Toast notifications were showing twice for the same error.
Root Cause: Toasts were being shown in two places:
- When the error first occurred (inside try block)
- Again in the catch block
Removed duplicate toast calls from the catch blocks in AuthContext.tsx. Now each error shows only ONE toast notification.
Before:
} catch (error) {
console.error('Login error:', error);
const message = error instanceof Error ? error.message : 'Login failed';
showToast({ title: 'Login error', description: message, variant: 'error' }); // ❌ Duplicate
throw error;
}After:
} catch (error) {
console.error('Login error:', error);
// Don't show toast here - it was already shown above ✅
throw error;
}Before:
} catch (error) {
console.error('Registration error:', error);
const message = error instanceof Error ? error.message : 'Registration failed';
showToast({ title: 'Signup error', description: message, variant: 'error' }); // ❌ Duplicate
throw error;
}After:
} catch (error) {
console.error('Registration error:', error);
// Don't show toast here - it was already shown above when the specific error occurred ✅
throw error;
}- User enters invalid credentials
- Supabase returns error
- Toast shown: "Login error - Invalid login credentials" ✅ (Once)
- Error thrown and logged
- Component handles the error (no additional toast)
- User tries to register with existing email
- Database returns constraint error
- Toast shown: "Signup error - This email is already registered..." ✅ (Once)
- Error thrown and logged
- Component handles the error (no additional toast)
- User logs in successfully
- Profile fetched successfully
- Toast shown: "Login successful - Welcome back!" ✅ (Once)
- User redirected to homepage
- ✅ Line 158: Initial auth error (invalid credentials)
- ✅ Line 182: Profile fetch error (user not found)
- ❌ Line 197: Removed (was duplicate)
- ✅ Line 212: Auth signup error
- ✅ Line 245: Database insert error (with specific error messages)
- ❌ Line 260: Removed (was duplicate)
- ✅ Line 188: Login success
- ✅ Line 255: Signup success
- ✅ Line 318: Logout success
User enters wrong password
→ Toast 1: "Login error - Invalid login credentials"
→ Toast 2: "Login error - Invalid login credentials" ❌ Duplicate
User enters wrong password
→ Toast: "Login error - Invalid login credentials" ✅ Only once
- ❌ Invalid credentials → 1 toast
- ❌ Email already exists → 1 toast
- ❌ PRN already registered → 1 toast
- ❌ Username already taken → 1 toast
- ❌ User profile not found → 1 toast
- ✅ Login successful → 1 toast
- ✅ Signup successful → 1 toast
- ✅ Logout successful → 1 toast
try {
const result = await someOperation();
if (error) {
showToast({ title: 'Error', description: message, variant: 'error' });
throw new Error(message);
}
showToast({ title: 'Success', description: message, variant: 'success' });
} catch (error) {
console.error('Operation error:', error);
// Don't show toast here - already shown above
throw error;
}try {
const result = await someOperation();
if (error) {
showToast({ title: 'Error', description: message, variant: 'error' }); // First toast
throw new Error(message);
}
} catch (error) {
console.error('Operation error:', error);
showToast({ title: 'Error', description: message, variant: 'error' }); // Duplicate toast ❌
throw error;
}- Better UX: Users see error message only once (cleaner)
- Less Clutter: No duplicate notifications stacking up
- Clearer Feedback: Single, clear error message
- Professional: Consistent notification behavior
- Login with wrong password → 1 error toast
- Login with non-existent email → 1 error toast
- Signup with existing email → 1 error toast
- Signup with existing PRN → 1 error toast
- Signup with existing username → 1 error toast
- Successful login → 1 success toast
- Successful signup → 1 success toast
- Successful logout → 1 success toast
Fixed: Toast notifications now show exactly once per event - no more duplicates!
Last Updated: October 2, 2025