[WIP] Investigate why /api/v1/admins/lends returns HTTP 401 Unauthorized#8
Draft
Copilot wants to merge 1 commit into
Draft
[WIP] Investigate why /api/v1/admins/lends returns HTTP 401 Unauthorized#8Copilot wants to merge 1 commit into
Copilot wants to merge 1 commit into
Conversation
Copilot stopped work on behalf of
tharindudev13 due to an error
April 25, 2026 08:57
Copilot stopped work on behalf of
tharindudev13 due to an error
April 25, 2026 08:58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.
Original prompt
Investigate why the endpoint
http://localhost:8090/api/v1/admins/lendsreturns HTTP 401 Unauthorized in repositorytharindudev13/Librariaonmain, even though it is expected to be publicly accessible (configured with permitAll).Scope:
Expected output:
/api/v1/admins/lends.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: There is an issue in this repository. In the lends tab of admin panel it doesn't show the lend details. Can you identify why?
Assistant: I’ll investigate the repo to find why the Admin Lends tab isn’t showing lend details, then report the root cause and fix.
To do that, I’ll inspect the relevant frontend/admin lends UI and backend lend APIs in
tharindudev13/Libraria.User: Ok. Do it
Assistant: Found it — the Admin Lends tab is not showing real lend details because it is currently hardcoded to dummy data and never calls the backend.
Why this causes the issue
AllLends.jsxdoes not fetch from any API endpoint.lendstate either.Related backend limitation
There is another likely blocker for true admin-wide lends:
For admin panel, you usually need something like
GET /api/v1/lends/all(all users’ lends). That endpoint is missing in current backend code.I also need to mention: code search results are capped (max 10 shown), so results may be incomplete. You can view more in GitHub search UI:
https://github.com/search?q=repo%3Atharindudev13%2FLibraria+lend+OR+lends+OR+lending+OR+loan+OR+borrow&type=code
If you want, I can now implement the fix (frontend + backend) and prepare a PR-ready patch.
User: No there is a authorization issue. The endpoint returns 401
Assistant: You’re right — this is an auth problem too. The admin lends UI currently doesn’t send a token, so protected endpoints will return 401 Unauthorized.
In your
AllLends.jsx, there is nofetchcall with anAuthorizationheader (unlikeBook.jsx, which does sendBearer ${token}).Why 401 happens
Authorization: Bearer <jwt>.What to fix
AllLends.jsx.localStorage(or Redux auth state).Authorization: Bearer ${token}Content-Type: application/jsonExample request shape:
If you want, I can give you a ready-to-paste full
AllLends.jsxthat fetches securely and handles 401 gracefully.User: Forget the AllLends.jsx I'm not using it anywhere. Just check why http://localhost:8090/api/v1/lends/lends this endpoint gives 401 even when it set to permitAll()
Assistant:
/api/v1/lends/lendsreturns 401 because that endpoint likely does not exist in your controller, so your `...This pull request was created from Copilot chat.