Skip to content

Conversation

@manavgup
Copy link
Owner

Summary

Fixes two critical authentication issues:

  1. TypeScript Error: AuthContext.tsx now handles null/undefined role values
  2. PostgreSQL UUID Error: Backend now uses proper UUID instead of token string for user_id

Problem

Issue 1: TypeScript Error

ERROR in src/contexts/AuthContext.tsx:127:41
TS2345: Argument of type 'string | null' is not assignable to parameter of type 'string'.

The mapBackendRole function expected a non-null string, but backend can return null for the role field.

Issue 2: PostgreSQL UUID Error

psycopg2.errors.InvalidTextRepresentation: invalid input syntax for type uuid: "dev-0000-0000-0000"
LINE 3: WHERE podcasts.user_id = 'dev-0000-0000-0000'::UUID

The code was incorrectly using MOCK_TOKEN (authentication token) as the user_id (database UUID), causing PostgreSQL to reject the invalid UUID format.

Solution

Frontend Fix (frontend/src/contexts/AuthContext.tsx)

  • Updated mapBackendRole function signature to accept string | null | undefined
  • Added null check that defaults to 'end_user' role

Backend Fix (backend/rag_solution/core/dependencies.py)

  • Import IdentityService
  • Use IdentityService.get_mock_user_id() to get proper UUID
  • Separate concerns: MOCK_TOKEN for auth, MOCK_USER_ID for database

Configuration (env.example)

  • Added MOCK_USER_ID=00000000-0000-0000-0000-000000000000 documentation
  • Clarified distinction between token (auth) and UUID (database)

Testing

  • TypeScript compiles without errors
  • Pre-commit hooks pass (ruff, formatting)
  • Podcast creation should now work without UUID errors
  • Manual testing: Create podcast with SKIP_AUTH=true

Changes

  • ✅ Handle null roles in frontend
  • ✅ Use proper UUID for mock user in backend
  • ✅ Document MOCK_USER_ID in env.example

Related Issues

Fixes podcast generation failures when using development authentication mode.

🤖 Generated with Claude Code

This commit fixes two critical authentication issues:

1. **TypeScript Error (frontend)**: AuthContext.tsx mapBackendRole function
   now handles null/undefined role values, preventing type errors when
   backend returns null role field.

2. **PostgreSQL UUID Error (backend)**: dependencies.py now uses proper
   UUID from IdentityService.get_mock_user_id() instead of MOCK_TOKEN
   string for user_id, fixing "invalid input syntax for type uuid" error.

3. **Configuration**: Added MOCK_USER_ID to env.example to document the
   distinction between MOCK_TOKEN (auth token) and MOCK_USER_ID (database UUID).

Changes:
- frontend/src/contexts/AuthContext.tsx: Handle null roles gracefully
- backend/rag_solution/core/dependencies.py: Use proper UUID for mock user
- env.example: Document MOCK_USER_ID with memorable all-zeros UUID

Fixes podcast creation and other operations that query user_id in PostgreSQL.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Contributor

🚀 Development Environment Options

This repository supports Dev Containers for a consistent development environment.

Option 1: GitHub Codespaces (Recommended)

Create a cloud-based development environment:

  1. Click the green Code button above
  2. Select the Codespaces tab
  3. Click Create codespace on fix/auth-uuid-issues
  4. Wait 2-3 minutes for environment setup
  5. Start coding with all tools pre-configured!

Option 2: VS Code Dev Containers (Local)

Use Dev Containers on your local machine:

  1. Install Docker Desktop
  2. Install VS Code
  3. Install the Dev Containers extension
  4. Clone this PR branch locally
  5. Open in VS Code and click "Reopen in Container" when prompted

Option 3: Traditional Local Setup

Set up the development environment manually:

# Clone the repository
git clone https://github.com/manavgup/rag_modulo.git
cd rag_modulo
git checkout fix/auth-uuid-issues

# Initialize development environment
make dev-init
make dev-build
make dev-up
make dev-validate

Available Commands

Once 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 linting

Services Available

When running make dev-up:


This automated message helps reviewers quickly set up the development environment.

@manavgup
Copy link
Owner Author

Closing this PR as the issues have been resolved through more comprehensive changes:

TypeScript null role handling - Already applied in current codebase (AuthContext.tsx:37-41)

PostgreSQL UUID validation - Superseded by PR #484 (unified user initialization architecture)

  • Mock users now created in database via ensure_mock_user_exists()
  • Proper UUID handling through authentication middleware
  • Consistent with OIDC and API user creation flows

Configuration - Simplified by removing MOCK_TOKEN from env.example

  • Token now hardcoded as "dev-bypass-auth" in backend
  • UUID generated dynamically by IdentityService

The root causes you identified were correct, but they've been addressed with a more robust, production-ready architecture. Thank you for spotting these issues!

See: PR #479, PR #484, and backend/core/authentication_middleware.py

@manavgup manavgup closed this Oct 26, 2025
@manavgup manavgup deleted the fix/auth-uuid-issues branch October 26, 2025 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants