auth-fixes #12

Merged
aetos merged 8 commits from auth-fixes into main 2026-07-19 14:47:30 +00:00
Owner

Summary

Wire spec-driven auth into the frontend. Auth config (server URL, paths) is extracted from the served OpenAPI spec by AppProvider. AuthProvider receives the config as a prop. 401 responses from both the main API and the auth server dispatch an auth:unauthorized event that triggers redirect to /login. Fix ProfileRoutes URL duplication bug.

Changes

Auth config from spec

  • main.jsxAppProvider wraps everything, loads spec, exposes authConfig. AuthProvider receives authConfig from useAppContext(). onUnauthorized passed to both AppProvider and AuthProvider wires navigate("/login").

401 handling

  • AppProvider.tsx — remove onUnauthorized prop (handled by AuthProvider's event listener instead, avoiding double-navigation).
  • useApi.ts — 401 response interceptor dispatches auth:unauthorized CustomEvent on window.

Profile routing fix

  • Admin.tsx:ProfileRoutes — replace nested <Routes> (which caused /profile/me/me URL duplication with React Router v6) with useLocation()/useNavigate() conditional rendering. Only allows /profile/me and /profile/me/edit.
  • Admin.tsx:ProfileComponentWrapper — replace pushState() + reload() with React Router navigate() for both onEdit and handleSubmit.

Debug logging

  • Temporary console logs at every navigation point for diagnosing remaining issues.
## Summary Wire spec-driven auth into the frontend. Auth config (server URL, paths) is extracted from the served OpenAPI spec by `AppProvider`. `AuthProvider` receives the config as a prop. 401 responses from both the main API and the auth server dispatch an `auth:unauthorized` event that triggers redirect to `/login`. Fix `ProfileRoutes` URL duplication bug. ## Changes ### Auth config from spec - **`main.jsx`** — `AppProvider` wraps everything, loads spec, exposes `authConfig`. `AuthProvider` receives `authConfig` from `useAppContext()`. `onUnauthorized` passed to both `AppProvider` and `AuthProvider` wires `navigate("/login")`. ### 401 handling - **`AppProvider.tsx`** — remove `onUnauthorized` prop (handled by `AuthProvider`'s event listener instead, avoiding double-navigation). - **`useApi.ts`** — 401 response interceptor dispatches `auth:unauthorized` CustomEvent on `window`. ### Profile routing fix - **`Admin.tsx:ProfileRoutes`** — replace nested `<Routes>` (which caused `/profile/me/me` URL duplication with React Router v6) with `useLocation()`/`useNavigate()` conditional rendering. Only allows `/profile/me` and `/profile/me/edit`. - **`Admin.tsx:ProfileComponentWrapper`** — replace `pushState() + reload()` with React Router `navigate()` for both `onEdit` and `handleSubmit`. ### Debug logging - Temporary console logs at every navigation point for diagnosing remaining issues.
aetos added 8 commits 2026-07-19 12:50:42 +00:00
- src/main.jsx: add /login, /register, /profile/* routes; wire
  profileComponents from react-auth; pass basePath to Admin
- src/Header.tsx: profile button nav to /profile/me; Login to /login
- src/openapi-config.ts: wire getToken and profileComponents
- react-auth local: sync ProfileCreate, ProfileEdit, ProfileView
- react-openapi local: sync all auth + x-profile changes
  (AppProvider, Admin, ProfileRoutes, SideMenu, types, hooks, etc.)
- main.jsx: remove VITE_AUTH_BASE_URL env var; add AppContent that
  reads authConfig from useAppContext() and passes to AuthProvider;
  reorder: AppProvider -> AuthProvider -> BrowserRouter
- sync react-openapi: AuthConfig type, extractAuthConfig, loading fix
- sync react-auth: authConfig prop, config-driven paths, server logout
- ProfileRoutes: removed nested <Routes> in favor of useLocation()/useNavigate()
  with strict allowlist for /profile/me and /profile/me/edit
- ProfileComponentWrapper: replaced pushState()+reload() with navigate()
- useApi: log 401 and non-401 errors
- contexts.tsx: log fetchCurrentUser lifecycle and auth:unauthorized events
- axios.ts: log auth server 401s
aetos merged commit 28cf6ccacf into main 2026-07-19 14:47:30 +00:00
aetos deleted branch auth-fixes 2026-07-19 14:47:31 +00:00
aetos referenced this issue from a commit 2026-07-19 14:47:32 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: apps/khata-ui#12
No description provided.