dfbf006 Refactor authentication error handling to use serror::Result and status codes
e23d193 Enable user query only when JWT is present
07e0380 Enable query execution in useRead only if JWT is present
6855f3e Revert backend auth changes - keep PR focused on frontend only
📊 Changes
1 file changed (+7 additions, -0 deletions)
View changed files
📝frontend/src/lib/hooks.ts (+7 -0)
📄 Description
Problem:
After implementing the improved HTTP status codes in the previous PR #841, I noticed that the frontend was still making unnecessary API calls when users weren't logged in. Every time someone visits the login page or any protected route without authentication, the frontend automatically tries to fetch user data and core info, resulting in a bunch of 400/401 errors flooding the browser console.
This isn't just annoying for developers - it also means we're hitting the backend with pointless requests that we know will fail. The main culprits were:
useUser() hook fetching /auth/GetUser even without JWT tokens
useRead() hook fetching /read/GetCoreInfo and other resources without authentication
Solution:
I've added authentication guards to the main query hooks to prevent these unnecessary API calls:
useUser Hook: Now checks if a JWT token exists before making the request
useRead Hook: Same deal - only fires when the user is actually authenticated
The fix uses React Query's enabled option to conditionally run queries:
enabled: hasJwt&&(config?.enabled!==false)
This means:
No more spam in the browser console when visiting the login page
Fewer pointless requests to the backend
Cleaner developer experience
Everything still works perfectly when users are logged in
The changes are backward compatible and don't break any existing functionality - they just prevent queries from running when they're guaranteed to fail anyway.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/moghtech/komodo/pull/842
**Author:** [@MP-Tool](https://github.com/MP-Tool)
**Created:** 9/12/2025
**Status:** ✅ Merged
**Merged:** 9/12/2025
**Merged by:** [@mbecker20](https://github.com/mbecker20)
**Base:** `1.19.4` ← **Head:** `fix/unnecessary-auth-api-queries`
---
### 📝 Commits (4)
- [`dfbf006`](https://github.com/moghtech/komodo/commit/dfbf00679ab3528a6afb917d5bfd178e7048d907) Refactor authentication error handling to use serror::Result and status codes
- [`e23d193`](https://github.com/moghtech/komodo/commit/e23d1933023bae08f924fca8bc00ac56583f53c1) Enable user query only when JWT is present
- [`07e0380`](https://github.com/moghtech/komodo/commit/07e03803880ba10fdd5ee522c5d533e484212252) Enable query execution in useRead only if JWT is present
- [`6855f3e`](https://github.com/moghtech/komodo/commit/6855f3e4d6c76f5e50a703936c7487ac0b140bc5) Revert backend auth changes - keep PR focused on frontend only
### 📊 Changes
**1 file changed** (+7 additions, -0 deletions)
<details>
<summary>View changed files</summary>
📝 `frontend/src/lib/hooks.ts` (+7 -0)
</details>
### 📄 Description
## Problem:
After implementing the improved HTTP status codes in the previous PR #841, I noticed that the frontend was still making unnecessary API calls when users weren't logged in. Every time someone visits the login page or any protected route without authentication, the frontend automatically tries to fetch user data and core info, resulting in a bunch of 400/401 errors flooding the browser console.
This isn't just annoying for developers - it also means we're hitting the backend with pointless requests that we know will fail. The main culprits were:
- `useUser()` hook fetching `/auth/GetUser` even without JWT tokens
- `useRead()` hook fetching `/read/GetCoreInfo` and other resources without authentication
## Solution:
I've added authentication guards to the main query hooks to prevent these unnecessary API calls:
1. **useUser Hook**: Now checks if a JWT token exists before making the request
2. **useRead Hook**: Same deal - only fires when the user is actually authenticated
The fix uses React Query's `enabled` option to conditionally run queries:
```typescript
enabled: hasJwt && (config?.enabled !== false)
```
This means:
- No more spam in the browser console when visiting the login page
- Fewer pointless requests to the backend
- Cleaner developer experience
- Everything still works perfectly when users are logged in
The changes are backward compatible and don't break any existing functionality - they just prevent queries from running when they're guaranteed to fail anyway.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/moghtech/komodo/pull/842
Author: @MP-Tool
Created: 9/12/2025
Status: ✅ Merged
Merged: 9/12/2025
Merged by: @mbecker20
Base:
1.19.4← Head:fix/unnecessary-auth-api-queries📝 Commits (4)
dfbf006Refactor authentication error handling to use serror::Result and status codese23d193Enable user query only when JWT is present07e0380Enable query execution in useRead only if JWT is present6855f3eRevert backend auth changes - keep PR focused on frontend only📊 Changes
1 file changed (+7 additions, -0 deletions)
View changed files
📝
frontend/src/lib/hooks.ts(+7 -0)📄 Description
Problem:
After implementing the improved HTTP status codes in the previous PR #841, I noticed that the frontend was still making unnecessary API calls when users weren't logged in. Every time someone visits the login page or any protected route without authentication, the frontend automatically tries to fetch user data and core info, resulting in a bunch of 400/401 errors flooding the browser console.
This isn't just annoying for developers - it also means we're hitting the backend with pointless requests that we know will fail. The main culprits were:
useUser()hook fetching/auth/GetUsereven without JWT tokensuseRead()hook fetching/read/GetCoreInfoand other resources without authenticationSolution:
I've added authentication guards to the main query hooks to prevent these unnecessary API calls:
The fix uses React Query's
enabledoption to conditionally run queries:This means:
The changes are backward compatible and don't break any existing functionality - they just prevent queries from running when they're guaranteed to fail anyway.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.