Commit Graph

6 Commits

Author SHA1 Message Date
Dongyu
a63fa22317 fix(web): localize the admin user management UI (#718)
Routes the remaining admin, sign-out, confirm-dialog and toast copy through i18next and adds the matching en/zh entries, so switching DeepTutor to Chinese no longer leaves account management in English.
2026-07-28 19:19:13 +08:00
Bingxi Zhao (Frank)
86ff120668 fix(profile): harden avatar fallback, admin ring in sidebar, dedupe auth-status fetch
Follow-up nits on the #573 profile/avatar work:
- UserAvatar: validate an icon marker's icon/color against the known sets and
  fall back to the deterministic avatar for unknown values. The backend
  _ICON_MARKER_RE accepts any [a-z0-9-] color, so a hand-set marker like
  "icon⭐bogus" previously rendered an invisible avatar
  (AVATAR_COLORS[unknown] === undefined).
- ProfileLink: pass role to UserAvatar so admins get the amber ring in the
  sidebar, matching the "amber ring at every size" intent.
- useAuthStatus: share one in-flight /api/v1/auth/status request across the
  hook's consumers (sidebar Admin/Logout/Profile links) so a page load makes a
  single call instead of one per consumer; cleared once settled so a later
  mount (after login/logout) refetches.

Verified: tsc, eslint, web node tests (142).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 01:11:48 +08:00
Bingxi Zhao (Frank)
2729b75dde Merge pull request #573: user profile page with avatar
Self-service /profile page (account info, icon/image avatar, sign out)
implementing the profile half of #553. Contributed by @IliaAvdeev.

Integration performed during merge onto current dev:
- Migrate ProfileLink and the profile page off the removed AUTH_ENABLED
  build-time export to runtime auth status (auth.ts was refactored on dev
  by #577). ProfileLink reads the full status via fetchAuthStatus (it needs
  username/avatar, which the useAuthStatus hook does not expose); the page
  gates on status.enabled.
- Resolve en/zh locale conflicts as a union of dev and PR keys.
- Honor EXIF orientation in createImageBitmap so the primary decode path
  matches the <img> fallback.
- Drop an unreachable AUTH_ENABLED render guard in the profile page.

Verified locally: tsc, eslint, ruff, web node tests (142), pytest
tests/multi_user (81 passed).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-20 23:57:21 +08:00
Bingxi Zhao (Frank)
37049c3d33 fix(web): resolve client auth state at runtime; size proxy body for uploads
Two gaps in the PR's frontend changes:

1. Client auth awareness was permanently false. api.ts/auth.ts read
   process.env.DEEPTUTOR_AUTH_ENABLED in browser code, but Next.js only inlines
   NEXT_PUBLIC_ vars into the bundle — so the Sign-out / Admin affordances never
   rendered and apiFetch's 401 -> /login redirect never fired when auth was on.
   Resolve auth state at runtime from the backend instead: fetchAuthStatus()
   records it via setRuntimeAuthEnabled(), and components observe it through the
   new useAuthStatus() hook. Works on Docker (read-only rootfs), PyPI, and dev
   with no build-time baking. (The server-side gate in proxy.ts is unaffected.)

2. KB document uploads >10MB were truncated. All /api/* now flows through the
   proxy, whose body buffer defaults to 10MB while the backend accepts 100MB
   (DocumentValidator.MAX_FILE_SIZE). Raise experimental.proxyClientMaxBodySize
   to 110MB so uploads aren't silently cut off.

Adds a regression test that a 401 does NOT redirect when auth is disabled.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-20 21:12:56 +08:00
Ilia Avdeev
7901368bb2 feat: user profile page with avatar (icons + image upload) 2026-06-14 17:43:13 +02:00
xor_xe
6688408800 feat: add optional auth with login, registration, and admin dashboard
Closes #227. Auth is disabled by default (AUTH_ENABLED=false) so
localhost usage is unaffected. Set AUTH_ENABLED=true +
NEXT_PUBLIC_AUTH_ENABLED=true to require login when hosting publicly.

Backend
- New deeptutor/services/auth.py: bcrypt password hashing, JWT
  create/decode, multi-user JSON store with role + created_at schema,
  auto-migration of old flat-hash format, first-user → admin bootstrap
- New deeptutor/api/routers/auth.py: require_auth / require_admin
  FastAPI dependencies; public endpoints /login /logout /status
  /register /is_first_user; admin-only /users /users/{u}/role
- deeptutor/api/main.py: Depends(require_auth) applied to all 14
  protected routers
- deeptutor/api/routers/unified_ws.py: cookie-based JWT check before
  ws.accept() when AUTH_ENABLED
- Added bcrypt>=4.0.0 and python-jose[cryptography]>=3.3.0 to
  requirements/server.txt and pyproject.toml extras

Frontend
- web/middleware.ts: route protection; /login and /register are public
- web/lib/api.ts: apiFetch wrapper — credentials:include + 401→login
- web/lib/auth.ts: login/logout/fetchAuthStatus + register() +
  checkIsFirstUser()
- web/lib/admin-api.ts: listUsers / deleteUser / setUserRole
- web/lib/session-api.ts: credentials:include on all fetches;
  expectJson redirects to /login on 401 instead of throwing
- web/app/(auth)/login/page.tsx: auto-redirects to /register when no
  users exist; shows success banner after registration
- web/app/(auth)/register/page.tsx: new registration page with
  first-user admin notice and password confirmation
- web/app/(admin)/admin/users/page.tsx: admin dashboard — user table
  with role toggle and delete; guards against self-demotion/deletion
- AdminLink and LogoutButton hidden when AUTH_ENABLED=false
- .env.example and README.md updated with auth vars and setup guide

Made-with: Cursor
2026-04-17 21:40:28 +04:00