Skip to content

Authentication Integration, CORS & DB Session Optimizations, and UI Profile Menu - #8

Merged
genius-0963 merged 3 commits into
mainfrom
fix-eslint-ssr-issues
Jul 29, 2026
Merged

genius-0963 merged 3 commits into
mainfrom
fix-eslint-ssr-issues

Conversation

@genius-0963

Copy link
Copy Markdown
Collaborator

Pull Request: Authentication Integration, CORS & DB Session Optimizations, and UI Profile Menu

Summary of Changes

This PR introduces critical architectural improvements across the frontend and backend of SelfSmart, including secure authenticated API requests, database connection pool auto-coercion for async SQLite, CORS middleware support, and frontend user profile section in the sidebar.


Key Changes

1. Dependencies & Configuration (chore)

  • Next.js API Rewrites: Added rewrite rules in frontend/next.config.ts to forward /api/* and /status calls to the backend service.
  • Dependencies: Added @radix-ui/react-avatar, @radix-ui/react-dropdown-menu, zod, aiolimiter, and updated locking files (uv.lock, package-lock.json).
  • Environment & Docs: Updated DATABASE_URL default dialect to sqlite+aiosqlite:///' in .env.example and updated startup docs in README.md.
  • Git Ignore: Ignored local runtime databases (*.db, *.sqlite3).

2. Backend API & Database Infrastructure (feat)

  • Async Database Engine: Updated src/db/session.py to auto-coerce sync SQLite URLs to sqlite+aiosqlite:/// and use NullPool for SQLite to prevent connection lock issues.
  • CORS Middleware: Explicitly enabled CORSMiddleware in src/api/main.py allowing origins like http://localhost:3000.
  • ORM Models: Fixed relationship definitions and foreign key string annotations on SubOrchestrator in src/db/models.py.
  • API Routes:
    • Updated src/api/routes/chat.py and src/api/routes/stats.py to source chat_runtime dependencies cleanly.
    • Compute live user feedback metrics (total, positive, satisfaction rate) directly from feedback.jsonl in the /stats endpoint.
  • HTTP Client: Updated FreeAPIClient in src/api/free_api_client.py for dynamic aiohttp.TCPConnector initialization without proxy issues.

3. Frontend Authentication & UI Enhancements (feat)

  • Authenticated Fetch Utility: Created authFetch (frontend/src/lib/authFetch.ts) to automatically attach JWT Authorization: Bearer <token> headers on API calls.
  • Store & Hooks Refactor: Updated useChatStore, useStreamingChat, and ChatMessage components to leverage authFetch.
  • Sidebar Profile & Logout: Added user avatar fallback, profile dropdown menu with sign-out action, and conversation counter in Sidebar.tsx.
  • Component Restructuring: Moved AuthWrapper into frontend/src/components/auth/AuthWrapper.tsx and updated local storage user name handling.

Verification Plan

Automated Tests

  • Ran backend application initialization check via scripts/test_app.py.

Manual Verification

  1. Start backend server: uvicorn src.api.main:app --reload
  2. Start frontend app: cd frontend && npm run dev
  3. Verify signing in sets token & full name in localStorage.
  4. Verify chat streaming and history requests include bearer token headers via authFetch.
  5. Verify sidebar profile dropdown shows user initials and signs out correctly.

@genius-0963
genius-0963 merged commit f193f33 into main Jul 29, 2026
2 of 6 checks passed
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.

1 participant