Skip to content

Add Email Validation Support (EmailStr + email-validator) #7

@Mattsface

Description

@Mattsface

Add Email Validation Support (EmailStr + email-validator)

🎯 Objective

Restore proper email validation in auth models by reintroducing EmailStr with correct email-validator dependency configuration.

📋 Background

During initial scaffold setup (Issue #1), we temporarily replaced EmailStr with str in auth models to unblock Docker builds due to missing email-validator dependency. This sub-issue restores proper email validation.

🔧 Technical Requirements

Dependencies

  • Add email-validator to pyproject.toml dependencies
  • OR use pydantic = { version = "^2.11", extras = ["email"] }
  • Ensure dependency resolves correctly in Poetry lock file
  • Verify package installs in Docker image

Code Changes

# In corner_pocket_backend/api/v1/auth.py
# Change from:
class RegisterIn(BaseModel):
    email: str  # Current temporary fix
    
# Back to:
from pydantic import EmailStr
class RegisterIn(BaseModel):
    email: EmailStr  # Proper validation

Docker Verification

  • Docker build succeeds with email-validator
  • poetry run pip list shows email-validator installed
  • Container runs without import errors

Acceptance Criteria

  1. Email Validation Works

    # Valid email - should succeed
    curl -X POST http://localhost:8000/api/v1/auth/register \
      -H 'Content-Type: application/json' \
      -d '{"email":"test@example.com","handle":"test","display_name":"Test","password":"pw"}'
    
    # Invalid email - should return 422 validation error
    curl -X POST http://localhost:8000/api/v1/auth/register \
      -H 'Content-Type: application/json' \
      -d '{"email":"invalid-email","handle":"test","display_name":"Test","password":"pw"}'
  2. Build & Deploy

    • Docker builds without cache successfully
    • No import errors on container startup
    • All existing smoke tests still pass
  3. Dependencies

    • poetry install works locally
    • poetry run python -c "from pydantic import EmailStr; print('OK')" succeeds
    • Docker image size doesn't increase significantly

🔄 Implementation Options

Option A: Direct dependency

[tool.poetry.dependencies]
email-validator = "^2.3.0"

Option B: Pydantic extra (recommended)

[tool.poetry.dependencies]
pydantic = { version = "^2.11", extras = ["email"] }

Option C: Force install in Dockerfile

RUN poetry install --no-root --only main \
 && poetry run pip install email-validator

📝 Files to Update

  • pyproject.toml - Add dependency
  • corner_pocket_backend/api/v1/auth.py - Restore EmailStr imports/usage
  • Verify no other files use email fields

⚠️ Risks

  • Dependency resolution conflicts (low risk)
  • Docker layer caching may need --no-cache rebuild
  • Regression in auth endpoints (mitigated by testing)

🧪 Testing

  • Unit test: valid email passes validation
  • Unit test: invalid email returns 422
  • Integration: full auth flow still works
  • Docker: build and smoke test

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions