mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-17 04:06:44 +02:00
Prevent duplicate user entries by handling empty emails
Fixes an issue where creating or editing users with empty email fields would violate a unique constraint in the database. The solution involves updating user routes to treat empty email strings as NULL, adjusting validation schemas, and providing a script to clean existing data. Replit-Commit-Author: Agent Replit-Commit-Session-Id: a8a78c07-e900-425c-a577-5b4c5894379d Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/a8a78c07-e900-425c-a577-5b4c5894379d/zoO1uWT
This commit is contained in:
1 parent
c77ea88e9d
commit
6a2e5aad05
5 files changed
+73
-22
No files matched your search
@@ -139,4 +139,14 @@ Preferred communication style: Simple, everyday language.
|
||||
- **Issue**: Admin password changes failed in production with ERR_MODULE_NOT_FOUND for localAuth.production
|
||||
- **Root Cause**: Dynamic imports in production needed `.js` extension for compiled files
|
||||
- **Solution**: Updated import paths to use `./localAuth.production.js` for production environment
|
||||
- **Result**: Password hashing now works correctly in production for user updates
|
||||
- **Result**: Password hashing now works correctly in production for user updates
|
||||
|
||||
#### Email Constraint Fix for User Management
|
||||
- **Issue**: Both user creation and editing failed with "duplicate key value violates unique constraint users_email_key" error
|
||||
- **Root Cause**: PostgreSQL treats empty strings (`""`) as unique values, but multiple users with empty emails violated uniqueness constraint
|
||||
- **Solution Implemented**:
|
||||
- Updated both POST `/api/users` (creation) and PUT `/api/users/:id` (editing) routes to convert empty emails to `NULL`
|
||||
- Enhanced validation schemas to accept `null` values for email fields
|
||||
- Created `fix-duplicate-empty-email.sql` script to clean existing database records
|
||||
- Improved error handling and logging for better production debugging
|
||||
- **Result**: Users can now be created and edited with optional email fields without constraint violations
|
||||
Reference in new issue
Block a user