Problem
Dual Authentication Systems: The codebase currently has two separate authentication implementations that don't integrate:
- Frontend: BetterAuth (third-party library) expecting its own table schema (
user, session, account, etc.)
- Backend: CodeFRAME custom auth (uses
users and sessions tables with bcrypt hashing)
Impact:
- E2E tests cannot validate the login UI flow (currently bypass with session cookies)
- Login form uses BetterAuth's
signIn() but test users exist in CodeFRAME's tables
- Dual systems increase maintenance complexity and security attack surface
Root Cause
- Schema Mismatch: BetterAuth creates
user (singular), CodeFRAME uses users (plural)
- Password Hashing: Different implementations (BetterAuth vs bcrypt)
- Session Management: Separate cookie/token strategies
Evidence
# E2E test logs
[BetterAuthError]: Failed to initialize database adapter
// Frontend: web-ui/src/lib/auth.ts
export const auth = betterAuth({
database: {
url: `file:${resolve(process.cwd(), "../.codeframe/state.db")}`,
type: "sqlite",
},
// ...
});
# Backend: tests/e2e/seed-test-data.py
cursor.execute("""
INSERT OR REPLACE INTO users (id, email, password_hash, ...)
VALUES (?, ?, ?, ...)
""", (1, "test@example.com", bcrypt_hash, ...))
Solution Options
Option A: Custom BetterAuth Adapter (Recommended)
Effort: ~4 hours
Approach: Create a custom database adapter that makes BetterAuth use CodeFRAME's existing tables
Pros:
- Keeps BetterAuth features (OAuth, 2FA, etc.)
- Single source of truth for user data
- Minimal frontend changes
Cons:
- Requires understanding BetterAuth internals
- Adapter maintenance burden
Option B: Replace BetterAuth with CodeFRAME Auth
Effort: ~6 hours
Approach: Remove BetterAuth, use CodeFRAME's auth API directly in LoginForm.tsx
Pros:
- Complete control over auth flow
- Simpler architecture
- No third-party dependency
Cons:
- Lose BetterAuth features
- More frontend API integration code
- Need to implement OAuth manually if needed later
Option C: Migrate CodeFRAME to BetterAuth Schema
Effort: ~8 hours
Approach: Change backend to use BetterAuth's schema, migrate existing users
Pros:
- Standardized auth solution
- Full BetterAuth feature set
- Good documentation
Cons:
- Breaking change for existing deployments
- Migration complexity
- Backend tightly coupled to frontend choice
Acceptance Criteria
Current Workaround
E2E tests use setTestUserSession() to bypass login by setting session cookies directly. This works for testing post-login flows but doesn't validate the login UI.
Migration path documented in test files:
// Replace setTestUserSession() with loginUser() after auth alignment
test.beforeEach(async ({ page }) => {
await loginUser(page); // Will work once auth is fixed
});
Related Files
web-ui/src/lib/auth.ts - BetterAuth configuration
web-ui/src/components/auth/LoginForm.tsx - Login UI (uses BetterAuth)
codeframe/persistence/database.py - CodeFRAME users/sessions tables
tests/e2e/auth-bypass.ts - Temporary bypass (delete after fix)
tests/e2e/test_auth_flow.spec.ts - Auth tests (1/4 passing)
Priority
P2 - High: Blocks full E2E test coverage and creates security/maintenance debt, but workaround exists for core user journey tests.
Problem
Dual Authentication Systems: The codebase currently has two separate authentication implementations that don't integrate:
user,session,account, etc.)usersandsessionstables with bcrypt hashing)Impact:
signIn()but test users exist in CodeFRAME's tablesRoot Cause
user(singular), CodeFRAME usesusers(plural)Evidence
Solution Options
Option A: Custom BetterAuth Adapter (Recommended)
Effort: ~4 hours
Approach: Create a custom database adapter that makes BetterAuth use CodeFRAME's existing tables
Pros:
Cons:
Option B: Replace BetterAuth with CodeFRAME Auth
Effort: ~6 hours
Approach: Remove BetterAuth, use CodeFRAME's auth API directly in
LoginForm.tsxPros:
Cons:
Option C: Migrate CodeFRAME to BetterAuth Schema
Effort: ~8 hours
Approach: Change backend to use BetterAuth's schema, migrate existing users
Pros:
Cons:
Acceptance Criteria
test@example.com) can login through the UItests/e2e/auth-bypass.tsdeleted (no longer needed)[BetterAuthError]in logsCurrent Workaround
E2E tests use
setTestUserSession()to bypass login by setting session cookies directly. This works for testing post-login flows but doesn't validate the login UI.Migration path documented in test files:
Related Files
web-ui/src/lib/auth.ts- BetterAuth configurationweb-ui/src/components/auth/LoginForm.tsx- Login UI (uses BetterAuth)codeframe/persistence/database.py- CodeFRAME users/sessions tablestests/e2e/auth-bypass.ts- Temporary bypass (delete after fix)tests/e2e/test_auth_flow.spec.ts- Auth tests (1/4 passing)Priority
P2 - High: Blocks full E2E test coverage and creates security/maintenance debt, but workaround exists for core user journey tests.