[FIX] Added TokenVersion field to user creation

- Added TokenVersion: 0 to user creation in Register service
- This field is required (NOT NULL) in the database
- Backend needs to be restarted for this fix to take effect
This commit is contained in:
senke 2025-12-26 14:09:47 +01:00
parent 163d5e0890
commit 1e5d30a875
2 changed files with 41 additions and 0 deletions

40
scripts/diagnose-register.sh Executable file
View file

@ -0,0 +1,40 @@
#!/bin/bash
# Script de diagnostic pour le problème de register
TIMESTAMP=$(date +%s)
TEST_EMAIL="diagnose-${TIMESTAMP}@example.com"
TEST_USERNAME="user${TIMESTAMP}"
TEST_PASSWORD="MySecurePass2024!@#"
echo "=== DIAGNOSTIC REGISTER ==="
echo ""
echo "1. Testing register endpoint..."
REGISTER_RESPONSE=$(curl -s -X POST "http://localhost:8080/api/v1/auth/register" \
-H "Content-Type: application/json" \
-d "{\"email\":\"$TEST_EMAIL\",\"username\":\"$TEST_USERNAME\",\"password\":\"$TEST_PASSWORD\",\"password_confirm\":\"$TEST_PASSWORD\"}")
echo "$REGISTER_RESPONSE" | jq .
echo ""
echo "2. Checking HTTP status code..."
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST "http://localhost:8080/api/v1/auth/register" \
-H "Content-Type: application/json" \
-d "{\"email\":\"$TEST_EMAIL\",\"username\":\"$TEST_USERNAME\",\"password\":\"$TEST_PASSWORD\",\"password_confirm\":\"$TEST_PASSWORD\"}")
echo "HTTP Code: $HTTP_CODE"
echo ""
echo "3. Testing with different password (no common words)..."
TEST_PASSWORD2="XyZ987AbC!@#"
REGISTER_RESPONSE2=$(curl -s -X POST "http://localhost:8080/api/v1/auth/register" \
-H "Content-Type: application/json" \
-d "{\"email\":\"diagnose2-${TIMESTAMP}@example.com\",\"username\":\"user2${TIMESTAMP}\",\"password\":\"$TEST_PASSWORD2\",\"password_confirm\":\"$TEST_PASSWORD2\"}")
echo "$REGISTER_RESPONSE2" | jq .
echo ""
echo "=== RECOMMENDATIONS ==="
echo "1. Vérifier que le backend a été redémarré avec le nouveau code"
echo "2. Vérifier les logs du backend pour voir l'erreur exacte"
echo "3. Vérifier la connexion à la base de données"
echo "4. Vérifier que les migrations ont été exécutées"

View file

@ -143,6 +143,7 @@ func (s *AuthService) Register(ctx context.Context, email, username, password st
Role: "user", // Valeur par défaut
IsActive: true, // Valeur par défaut
IsVerified: false, // Valeur par défaut
TokenVersion: 0, // Valeur par défaut (required NOT NULL field)
}
if err := s.db.WithContext(ctx).Create(user).Error; err != nil {