fix(user): Add email-based user lookup to prevent duplicates (#719)#721
fix(user): Add email-based user lookup to prevent duplicates (#719)#721
Conversation
When using trusted proxy authentication with X-Authenticated-User header, users were being looked up by ibm_id instead of email. This caused duplicate users when the existing user had a different ibm_id than their email. Changes: - Add get_by_email() method to UserRepository for email-based lookup - Add get_user_by_email() and get_or_create_by_email() to UserService - Update MCP auth to use service layer instead of direct DB queries - Catch specific exceptions (DomainError, RepositoryError) instead of general Exception The get_or_create_by_email() method first checks if a user exists by email, and only creates a new user if not found. This prevents duplicates when authenticating via trusted proxy. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🚀 Development Environment OptionsThis repository supports Dev Containers for a consistent development environment. Option 1: GitHub Codespaces (Recommended)Create a cloud-based development environment:
Option 2: VS Code Dev Containers (Local)Use Dev Containers on your local machine:
Option 3: Traditional Local SetupSet up the development environment manually: # Clone the repository
git clone https://github.com/manavgup/rag_modulo.git
cd rag_modulo
git checkout fix/user-email-lookup-719
# Initialize development environment
make dev-init
make dev-build
make dev-up
make dev-validateAvailable CommandsOnce in your development environment: make help # Show all available commands
make dev-validate # Validate environment setup
make test-atomic # Run atomic tests
make test-unit # Run unit tests
make lint # Run lintingServices AvailableWhen running
This automated message helps reviewers quickly set up the development environment. |
Code Review - PR #721: Email-Based User LookupOverviewThis PR adds email-based user lookup functionality to prevent duplicate user creation in trusted proxy authentication scenarios. The implementation follows the repository pattern and service layer architecture consistently. ✅ Strengths
|
Summary
get_by_email()method to UserRepository for email-based user lookupget_user_by_email()andget_or_create_by_email()methods to UserServiceDomainError,RepositoryError) instead of generalExceptionProblem
When using trusted proxy authentication with the
X-Authenticated-Userheader, users were being looked up byibm_idinstead of email. This caused duplicate users when the existing user had a differentibm_idthan their email address.Solution
The
get_or_create_by_email()method now:ibm_idfor new users created via trusted proxyThis prevents duplicate user creation while maintaining backward compatibility with existing users.
Test plan
Fixes #719
🤖 Generated with Claude Code