Commit e2c3727
authored
Centralize Authentication (#9593)
* Introduce centralized authentication context to manage auth state and replace scattered authentication logic in the frontend.
* Refactor `useUser` and `ConfigProvider` hooks to use `useCallback` and `useAPI`, streamlining state management and simplifying configuration retrieval logic.
* Consolidate authentication status and logic into `authContext`, remove redundant `status.ts`, and rename `RequireAuth` to `RequiresAuth` for consistency.
* Refactor authentication logic by consolidating `markAuthenticated` and `markUnauthenticated` into `setAuthStatus`, simplifying auth state management.
* Refactor login flow to use `RedirectIfAuthenticated` component, centralizing auth redirection logic and simplifying `login.tsx`.
* Refactor `RedirectIfAuthenticated` to use a functional component and simplify child rendering logic.
* Refactor `authContext` to use functional components, arrow functions, and improve readability of authentication logic.
* Refactor `RequiresAuth` to use `React.FC` and arrow function for consistency with functional component style.
* Refactor `authContext` to reorder `AuthContext` and `AuthContextType` definitions for improved readability and organization.
* Refactor login flow to handle redirect authentication with `useEffect` and `setAuthStatus`, simplifying and centralizing auth logic.
* Refactor `login.tsx` to simplify `next` variable assignment by removing redundant type assertions.
* Refactor `login.tsx` to reorder conditional logic for readability and maintain consistency in authentication flow.
* Refactor `login.tsx` to replace `useEffect` with direct conditional navigation logic and simplify SSO handling flow.
* Refactor `login.tsx` to remove unused `useEffect` import.
* Refactor `login.tsx` to remove redundant type assertions in `next` variable assignment.
* Refactor `login.tsx` to remove unused authenticated redirect logic for cleaner and simplified authentication flow.
* Refactor `login.tsx` to remove unused imports and redundant `useAuth` destructuring for cleaner code.
* Refactor authentication flow in `login.tsx` and `requiresAuth.tsx` to centralize redirect logic and ensure consistent handling of authenticated and unauthenticated states.
* Refactor `login.tsx` to simplify `next` variable assignment by removing redundant parentheses.
* Refactor `AuthProvider` to use `useEffect` for dynamic authentication status and simplify `login.tsx` by removing unused redirect logic.
* Refactor `api.jsx` to reset request state on authentication error for consistent error handling and cleaner unmount logic.
* Refactor `requiresAuth.tsx` to simplify authentication flow by removing unused API call and redundant state handling.
* Refactor `authContext.tsx` to streamline `AuthProvider`, remove `useEffect`, and simplify initial auth status handling.
* Refactor `navbar.jsx` to simplify logout flow by removing conditional navigation logic.
* Refactor `navbar.jsx` and `requiresAuth.tsx` to clean up unused imports and simplify `next` variable assignment with hash handling.
* Refactor `index.jsx` to adjust route nesting by relocating `index` route within `RequiresAuth` for cleaner route structure.
* Refactor `index.jsx` to relocate fallback route for improved route structure and eliminate redundancy.
* Refactor `layout.tsx` to remove unnecessary `useEffect` and streamline RBAC alert dismissal logic.
* Refactor `api.jsx` to improve unmount logic by adding `isMounted` checks and streamline request state handling on authentication errors.
* Refactor `authContext.tsx`, `api.jsx`, and `user.jsx` to introduce `UNKNOWN` auth status, improve auth status synchronization, and streamline user fetching logic.
* Refactor `authContext.tsx` to simplify `AuthProvider` by replacing `readInitialStatus` with direct `UNKNOWN` initialization.
* Refactor `user.jsx` to handle `UNKNOWN` auth status, improve user-fetching logic, and optimize auth state synchronization.
* Refactor `navbar.jsx`, `login.tsx`, `api.jsx`, and `user.jsx` to improve logout flow by leveraging `sessionStorage` for state management and ensuring clean API handling during logout.
* Simplify logout logic in `navbar.jsx` by replacing hardcoded URL with `logoutUrl` variable.
* Remove `sessionStorage`-based logout flow logic from `navbar.jsx`, `login.tsx`, `api.jsx`, and `user.jsx` for simplification and cleanup.
* Remove unused `useEffect` import from `login.tsx`.
* Improve logout flow by finalizing `sessionStorage` logic in `navbar.jsx`, `login.tsx`, `api.jsx`, and `user.jsx` to ensure clean state management and prevent race conditions.
* Simplify logout logic in `navbar.jsx` by using `window.location.replace` instead of `window.location` for better URL handling.
* Remove `sessionStorage`-based logout flow logic from `navbar.jsx`, `login.tsx`, `api.jsx`, and `user.jsx` to simplify and streamline state management.
* Remove unused `auth` and `useAuth` imports from `navbar.jsx` and remove commented-out legacy `useUser` logic from `user.jsx` for cleanup.
* Cleanup `api.jsx` by simplifying `useEffect` cleanup logic and consistent formatting adjustments.
* Add missing newline at end of `api.jsx` for consistency.
* Fix inconsistent object formatting in `api.jsx` within `setRequest` function.
* Refactor `login.tsx` to streamline URL query handling and `ConfigProvider` for improved memoization efficiency.
* Refactor `useUser` to simplify authentication status logic and update logout flow in `navbar.jsx` to clear user state via `auth.clearCurrentUser`.
* Refactor `useUser` to enhance authentication status handling by improving `fetcher` logic and ensuring accurate status updates.
* Refactor `useUser` to optimize `fetcher` logic and streamline authentication status updates.
* Update `RequiresAuth` to display loading state when user authentication is in progress
* Refactor `RequiresAuth` and `useUser` to improve user authentication flow by optimizing loading state handling and revalidation logic.
* Refactor `useUser` to simplify `fetcher` logic by removing unnecessary dependencies and improving readability.
* Refactor `useUser` to handle unauthenticated status explicitly in `fetcher` logic and update dependencies for improved accuracy.
* add changes
* Fix inconsistent formatting in `onClick` handler within `navbar.jsx`.
* Remove unused `logged` prop from `Layout` in `create-user-with-password.jsx`.
* Add `logged` prop to `Layout` in `create-user-with-password.jsx` to ensure proper rendering
* changes
* Refactor login redirection logic to ensure `state` resets correctly and simplify unauthenticated error handling in API hook.
* Remove unused `status` destructure in `useAPI` hook to clean up code.
* Refactor login redirection logic and simplify unauthenticated error handling in `useAPI` hook.
* Fix typo in `Logout` label text within `navbar.jsx`.
* Fix typo in `Logout` label and add missing return statement in `useAPI` hook
* Refactor `RequiresAuth` to use `AUTH_STATUS` and centralize authentication state handling
* Simplify unauthenticated user check in `RequiresAuth` component.
* Refactor `useUser` hook to improve cache validation and enhance loading state tracking in `RequiresAuth`.
* Add fallback to `getCurrentUser` in login flow to handle edge cases
* Refactor `useUser` hook and login flow to streamline `getCurrentUser` handling and improve state management.
* Enhance `useUser` hook with `pageshow` handling and optimize authentication state updates. Simplify `RequiresAuth` loading logic.
* Refactor `useUser` hook to remove unused `status`, streamline `fetcher` logic, and enhance `loading` state tracking in `RequiresAuth`.
* Remove redundant `getCurrentUser` call in login flow to streamline authentication handling.
* Refactor authentication flow to standardize `AUTH_STATUS` usage and improve state management in `RequiresAuth` and `useUser`.
* Simplify logout flow by removing redundant authentication state updates.
* Remove unused `setAuthStatus` and clean up imports in `navbar.jsx`.
* Update logout flow to set `AUTH_STATUS.UNAUTHENTICATED` before redirecting to logout URL.
* Simplify logout flow by removing `setAuthStatus`, cleaning up imports, and directly handling user state reset.
* Set `AUTH_STATUS.UNAUTHENTICATED` in logout flow and clean up imports in `navbar.jsx`.
* Add `setAuthStatus` to `navbar.jsx` and update imports for authentication state management.
* Simplify logout flow by replacing `onClick` logic with direct `href` to `logoutUrl`.
* Update logout item to replace URL in history before redirect
* Remove redundant comment in `RequiresAuth` component.
* Refactor authentication flow to check session cookies before making user state transitions.
* Update logout flow to set `AUTH_STATUS.UNAUTHENTICATED` and use `window.location.replace` for redirect.
* Comment out unused `auth` import in `navbar.jsx`.
* Reset user state on logout by calling `auth.clearCurrentUser`.
* Refactor auth flow by simplifying cookie checks, consolidating logout logic, and streamlining user state updates.
* Update logout flow: clear user state and set `AUTH_STATUS.UNAUTHENTICATED` in `navbar.jsx`.
* Simplify logout item by replacing `onClick` logic with direct URL handling and timestamp parameter.
* Remove unused `auth` and `AUTH_STATUS` imports in `navbar.jsx`.
* Refactor authentication flow: streamline session cookie checks, consolidate auth logic, and enhance user redirection handling.
* Remove unused `auth` and `AUTH_STATUS` imports from `navbar.jsx`.
* Remove unused `useEffect` and `pageshow` listener for session cookie checks in `requiresAuth.tsx`.
* Remove unused `useEffect` import from `requiresAuth.tsx`.
* Update logout flow: clear user state, set `AUTH_STATUS.UNAUTHENTICATED`, and redirect to logout URL in `navbar.jsx`.
* Refactor authentication flow: unify session cookie checks, simplify state management, and remove redundant logic in `navbar.jsx`, `requiresAuth.tsx`, and `user.jsx`.
* Remove unused `auth` import from `navbar.jsx`.
* Refactor logout flow: extract `handleLogout` function, update redirection logic, and clean up state management in `navbar.jsx`.
* Remove unused `happy-dom` router import and consolidate `LOGIN_COOKIE_NAMES` definition.
* Refactor logout logic: replace router navigation with `window.history.replaceState`, clean up `auth.clearCurrentUser` call.
* Refactor logout and authentication flow: simplify `handleLogout` logic in `navbar.jsx`, add cleanup for `unload` event in `requiresAuth.tsx`.
* Remove unused `auth` import and redundant `as="button"` prop from `navbar.jsx`.
* Add BFCache handling to `requiresAuth.tsx` and update session cookie check logic.
* Refactor authentication flow: simplify session handling, remove redundant session cookie checks, and clean up `useUser` and `requiresAuth.tsx` logic.
* Add BFCache and session cookie handling logic to `requiresAuth.tsx` to ensure proper authentication redirection.
* Add eslint-disable comment for unused `__lakefsBFGuard` declaration in `requiresAuth.tsx`.
* Remove eslint-disable comment for unused `__lakefsBFGuard` declaration and format global interface in `requiresAuth.tsx`.
* Update `onPageShow` type in `requiresAuth.tsx` for better type safety
* Remove unused BFCache and session cookie handling logic from `requiresAuth.tsx` to simplify authentication flow.
* Refactor logout logic in `navbar.jsx`: add `auth.clearCurrentUser` call before resetting auth status.
* Enhance authentication redirection in `useAPI`: add 401 error handling with navigation to login page and simplify `useUser` logic.
* Refactor authentication redirection in `useAPI`: consolidate public auth route checks and enhance `next` state handling.
* Refactor `useAPI` and `authContext`: consolidate unauthorized handling logic into `onUnauthorized` callback for improved reuse and clarity.
* Remove unused `AUTH_STATUS` and `useNavigate` imports from `api.jsx` for cleaner codebase.
* Refactor `useUser` and `requiresAuth`: remove `useLocation` dependency and simplify auth status handling logic.
* Refactor `requiresAuth`: replace `useAuth` with `useUser` for simplified and consistent authentication handling.
* Comment out redundant `setRequest` and `return` logic in 401 error handling within `useAPI`.
* Remove commented-out redundant `setRequest` and `return` logic in `useAPI` 401 error handling
* Enhance login redirection: persist `next` state in sessionStorage and improve fallback login URL handling.
* Refactor login redirection: consolidate `next` state handling and streamline sessionStorage usage.
* Refactor login redirection: streamline `redirected` handling, normalize URLs, and enhance `next` state persistence logic.
* Refactor login redirection: simplify `next` state handling and remove unnecessary try-catch block.
* Refactor login redirection: consolidate rendering logic, centralize auth checks, and simplify `next` state handling.
* Refactor login redirection: remove redundant `typeof` check for `next` state.
* Refactor login redirection: extract `withNext` function, enhance `next` state handling, and improve redirection cleanup logic.
* Enhance login redirection: add `useEffect` to handle `post_login_next` navigation from sessionStorage.
* Refactor login flow: introduce `DEFAULT_LOGIN_CONFIG`, streamline login config handling, and consolidate rendering logic.
* Refactor login flow: streamline rendering logic, remove `DEFAULT_LOGIN_CONFIG`, and enhance redirection handling with `Navigate`.
* Refactor login redirection: simplify loading state, enhance `setup` redirection logic, and improve query string handling.
* Refactor login flow: extract `getLoginIntent`, introduce `DoNavigate` and `ExternalRedirect` components, and enhance `next` state handling.
* Refactor navbar and login route: remove unused auth context references and simplify redirection logic.
* Refactor authentication handling: rename `setAuthStatus` to `setStatus`, replace `AUTH_STATUS.UNKNOWN` with `AUTH_STATUS.PENDING`, and centralize utility functions for redirection and route management.
* Refactor authentication flow: replace `buildNextFromWindow` with `getCurrentRelativeUrl`, unify `lakefs_post_login_next` handling, and centralize redirection utilities for consistency.
* Refactor authentication flow: remove `useUser` hook, centralize user management in `authContext`, and update components accordingly.
* commit
* Enhance authContext: refresh user data on `pageshow` for better session consistency after page restores.
* Refactor authentication handling: rename `onUnauthorized` to `onUnauthenticated`, improve user refresh logic, and streamline login flow by removing unused utilities and centralizing route management.
* Refactor authContext and navbar: remove redundant dependencies, disable cache for user refresh, and improve logout redirection logic.
* Format imports in `authContext.tsx` for consistent styling.
* commit
* changes1 parent f10b322 commit e2c3727
File tree
15 files changed
+353
-219
lines changed- webui/src
- lib
- auth
- components
- auth
- hooks
- pages
- auth
- users
- user
15 files changed
+353
-219
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | 11 | | |
14 | 12 | | |
15 | 13 | | |
| |||
20 | 18 | | |
21 | 19 | | |
22 | 20 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | 21 | | |
40 | 22 | | |
41 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
9 | 11 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
| 12 | + | |
16 | 13 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
26 | 19 | | |
27 | 20 | | |
28 | 21 | | |
29 | | - | |
| 22 | + | |
30 | 23 | | |
31 | | - | |
| 24 | + | |
32 | 25 | | |
33 | 26 | | |
34 | 27 | | |
35 | 28 | | |
36 | 29 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 30 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | 2 | | |
5 | 3 | | |
6 | 4 | | |
| |||
9 | 7 | | |
10 | 8 | | |
11 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | | - | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | | - | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
40 | | - | |
| 42 | + | |
41 | 43 | | |
42 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
43 | 47 | | |
44 | 48 | | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
48 | | - | |
49 | | - | |
50 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
51 | 55 | | |
52 | 56 | | |
53 | 57 | | |
| |||
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
66 | | - | |
67 | | - | |
| 70 | + | |
| 71 | + | |
68 | 72 | | |
69 | 73 | | |
70 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | 53 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 54 | + | |
75 | 55 | | |
76 | 56 | | |
77 | 57 | | |
78 | 58 | | |
79 | 59 | | |
80 | 60 | | |
81 | 61 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
| 62 | + | |
| 63 | + | |
87 | 64 | | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
93 | 70 | | |
94 | 71 | | |
95 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
| 5 | + | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
60 | | - | |
61 | | - | |
| 61 | + | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
72 | 75 | | |
73 | 76 | | |
74 | | - | |
| 77 | + | |
75 | 78 | | |
76 | 79 | | |
77 | 80 | | |
| |||
0 commit comments