Do now show login error before flow starts#392
Conversation
WalkthroughModified HTTP 401 error handling in the authentication context to immediately initiate login flow when not on login or callback pages, replacing previous logic that extracted error messages before conditionally redirecting. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/standalone/src/app/context/AuthContext.ts (1)
104-111: 401 handling now matches the desired login-flow behaviorThe new
isOnAuthPagecheck and early return on 401 correctly avoid flashing an authentication error on initial navigation: non-auth routes redirect straight to/loginwithout settingerror, while/callbackstill shows a meaningful error if/inforeturns 401 after a failed login.One small optional cleanup: since the hook exits early on Line 36 when
window.location.pathname === '/login', the/logincase will never reach this 401 block, so including'/login'inisOnAuthPageis redundant. You could simplify it to justwindow.location.pathname === '/callback'or extract a sharedisOnAuthPage()helper used in both places, but this is purely cosmetic.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/standalone/src/app/context/AuthContext.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: celdrake
Repo: flightctl/flightctl-ui PR: 376
File: libs/ui-components/src/components/Repository/CreateRepository/CreateRepositoryForm.tsx:274-275
Timestamp: 2025-11-17T15:53:01.194Z
Learning: In PR #376 (flightctl/flightctl-ui), the permission system was updated to fetch all user permissions once at login via the Flight Control API. The `checkPermissions` function from `usePermissionsContext` is a pure calculation on cached permission arrays, not an async fetch, so loading state handling is generally not required at individual component call sites.
Learnt from: rawagner
Repo: flightctl/flightctl-ui PR: 209
File: apps/standalone/src/app/utils/apiCalls.ts:14-16
Timestamp: 2025-02-18T12:04:42.579Z
Learning: In the flightctl-ui codebase, error handling for API calls (like logout) is implemented by the caller rather than within the API utility functions themselves.
Learnt from: rawagner
Repo: flightctl/flightctl-ui PR: 209
File: apps/standalone/src/app/utils/apiCalls.ts:14-16
Timestamp: 2025-02-18T12:04:42.579Z
Learning: In the flightctl-ui codebase, error handling for API calls follows a React pattern where the caller component (e.g., AppToolbar.tsx) implements try-catch blocks and manages error states, rather than handling errors within the API utility functions themselves.
🧬 Code graph analysis (1)
apps/standalone/src/app/context/AuthContext.ts (1)
apps/standalone/src/app/utils/apiCalls.ts (1)
redirectToLogin(58-60)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: integration-tests
- GitHub Check: Build ocp plugin
- GitHub Check: Build
- GitHub Check: Lint
When the user first went to the UI page, we'd briefly show an error as "getUserInfo" returned statusCode 401.
Now we will start the login flow and the errors will be shown if the login fails.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.