Problem
The user normalization logic is duplicated in 4 places inside authContext.tsx (login, verifyEmail, googleLogin, verifyToken). Each function repeats the same ~15 lines of code to map raw user data into the User type.
This duplication violates the DRY principle, makes the code harder to maintain, and increases the risk of inconsistencies (e.g., rating default is 1200 in one place and 1500 in another).
Solution
Create a reusable normalizeUser utility function that accepts user data and optional overrides. This will reduce each occurrence to a single line and centralize future updates.
Impact
- Removes ~60 lines of duplicate code
- Improves maintainability
- Reduces bugs from copy-paste errors
Implementation Outline
- Add
frontend/src/utils/normalizeUser.ts with the utility function
- Update
authContext.tsx to use it in the 4 mentioned functions
- Test all authentication flows (login, signup, Google login, email verification)
Problem
The user normalization logic is duplicated in 4 places inside
authContext.tsx(login,verifyEmail,googleLogin,verifyToken). Each function repeats the same ~15 lines of code to map raw user data into theUsertype.This duplication violates the DRY principle, makes the code harder to maintain, and increases the risk of inconsistencies (e.g.,
ratingdefault is1200in one place and1500in another).Solution
Create a reusable
normalizeUserutility function that accepts user data and optional overrides. This will reduce each occurrence to a single line and centralize future updates.Impact
Implementation Outline
frontend/src/utils/normalizeUser.tswith the utility functionauthContext.tsxto use it in the 4 mentioned functions