From 28cf6ccacfb305b4f5ac7f17a8a1d37f8d46bf4f Mon Sep 17 00:00:00 2001 From: Vishesh 'ironeagle' Bangotra Date: Sun, 19 Jul 2026 14:47:30 +0000 Subject: [PATCH] auth-fixes (#12) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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 `` (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. Reviewed-on: https://git.aetoskia.com/apps/khata-ui/pulls/12 Co-authored-by: Vishesh 'ironeagle' Bangotra Co-committed-by: Vishesh 'ironeagle' Bangotra --- .run/Install Deps.run.xml | 2 +- .run/Run Dev.run.xml | 5 +- react-auth/ProfileCreate.tsx | 122 +++++++++++ react-auth/ProfileEdit.tsx | 111 ++++++++++ react-auth/ProfileView.tsx | 85 ++++++++ react-auth/axios.ts | 2 + react-auth/contexts.tsx | 67 ++++-- react-auth/index.ts | 7 + react-openapi/index.ts | 5 +- react-openapi/src/components/Admin.tsx | 190 +++++++++++++++++- react-openapi/src/components/Layout.tsx | 2 +- react-openapi/src/components/SideMenu.tsx | 2 +- react-openapi/src/context/AppContext.tsx | 5 +- react-openapi/src/context/AppProvider.tsx | 54 ++++- react-openapi/src/hooks/useApi.ts | 18 +- react-openapi/src/spec-validator.ts | 5 + .../src/transformers/resource-config.ts | 7 + react-openapi/src/types.ts | 25 +++ src/Header.tsx | 4 +- src/main.jsx | 133 ++++++++---- src/openapi-config.ts | 4 +- 21 files changed, 774 insertions(+), 81 deletions(-) create mode 100644 react-auth/ProfileCreate.tsx create mode 100644 react-auth/ProfileEdit.tsx create mode 100644 react-auth/ProfileView.tsx diff --git a/.run/Install Deps.run.xml b/.run/Install Deps.run.xml index 1db18f4..a748924 100644 --- a/.run/Install Deps.run.xml +++ b/.run/Install Deps.run.xml @@ -1,6 +1,6 @@ - + diff --git a/.run/Run Dev.run.xml b/.run/Run Dev.run.xml index 97c0215..0f2b8c6 100644 --- a/.run/Run Dev.run.xml +++ b/.run/Run Dev.run.xml @@ -1,12 +1,15 @@ - +