AOSSIE-Org / AOSSIE-Org/DebateAI

Refactor: Create reusable normalizeUser utility to reduce code duplication

Ouverte
#422 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
TypeScript
Étoiles
84
Forks
198
Merge moyen
2 j 19 h
PR mergées (30 j)
30

Description

## 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
1. Add `frontend/src/utils/normalizeUser.ts` with the utility function
2. Update `authContext.tsx` to use it in the 4 mentioned functions
3. Test all authentication flows (login, signup, Google login, email verification)

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Start by reading frontend/src/authContext.tsx, focusing on the normalization logic in login, verifyEmail, googleLogin, and verifyToken. Compare the four mappings and the differing rating defaults before reviewing the new utility location at frontend/src/utils/normalizeUser.ts. Done means all four flows use the shared utility and login, signup, Google login, and email verification still work.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
typescript
Domaine
authentication, frontend
Type d'issue
Refactorisation
Difficulté
3/5
Temps estimé
1-2 jours
Activité
Active
Clarté
Clairement spécifiée
Accessibilité débutants
76/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.