-
Notifications
You must be signed in to change notification settings - Fork 10
refactor: migrate /api/account endpoints to Recoup-API #1478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: test
Are you sure you want to change the base?
refactor: migrate /api/account endpoints to Recoup-API #1478
Conversation
- Update useUser.tsx to use Recoup-API for account creation and updates - Update useOrgSettings.ts to use Recoup-API for account updates - Remove /api/account, /api/account/update, /api/account/add_artist endpoints - Use PATCH method for account updates per new API design Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional Suggestion:
The response structure expected by the PATCH /api/accounts endpoint appears to be incorrect, matching the same issue in useUser.tsx. The code should access data.account instead of data.data.
View Details
📝 Patch Details
diff --git a/hooks/useOrgSettings.ts b/hooks/useOrgSettings.ts
index ce91da1b..d429f69e 100644
--- a/hooks/useOrgSettings.ts
+++ b/hooks/useOrgSettings.ts
@@ -155,7 +155,7 @@ const useOrgSettings = (orgId: string | null) => {
if (response.ok) {
const data = await response.json();
- setOrgData(data.data);
+ setOrgData(data.account);
// Invalidate org list cache so sidebar shows updated image/name immediately
await queryClient.invalidateQueries({ queryKey: ["accountOrganizations"] });
return true;
diff --git a/hooks/useUser.tsx b/hooks/useUser.tsx
index b2899d16..de3cb62a 100644
--- a/hooks/useUser.tsx
+++ b/hooks/useUser.tsx
@@ -86,7 +86,7 @@ const useUser = () => {
}
const data = await response.json();
- setUserData(data.data);
+ setUserData(data.account);
setIsModalOpen(false);
} catch {
// Error handled silently
@@ -139,14 +139,14 @@ const useUser = () => {
}
const data = await response.json();
- setUserData(data.data);
- setImage(data.data?.image || "");
- setInstruction(data.data?.instruction || "");
- setName(data?.data?.name || "");
- setOrganization(data?.data?.organization || "");
- setJobTitle(data?.data?.job_title || "");
- setRoleType(data?.data?.role_type || "");
- setCompanyName(data?.data?.company_name || "");
+ setUserData(data.account);
+ setImage(data.account?.image || "");
+ setInstruction(data.account?.instruction || "");
+ setName(data?.account?.name || "");
+ setOrganization(data?.account?.organization || "");
+ setJobTitle(data?.account?.job_title || "");
+ setRoleType(data?.account?.role_type || "");
+ setCompanyName(data?.account?.company_name || "");
};
if (!email && !address) return;
init();
Analysis
Incorrect API response field access for Recoup-API /api/accounts endpoint
What fails: The PATCH endpoint response handling in useOrgSettings.ts (line 157) and useUser.tsx (lines 88 and 141) incorrectly accesses data.data instead of data.account, causing the organization and user data to be set to undefined after updates.
How to reproduce:
- In
useOrgSettings.ts, call thesave()function to update organization settings via PATCH/api/accounts - Observe that after the PATCH request completes,
orgDatabecomesnullinstead of containing the updated account information
Result: Organization settings persist on the server but the UI state is cleared, losing the loaded organization data and breaking the settings display.
Expected: The PATCH /api/accounts endpoint returns the same response structure as the GET /api/accounts/{id} endpoint, which follows the format { status: "success", account: {...} }. The response field should be accessed via data.account, consistent with the GET endpoint implementation (useOrgSettings.ts line 72) which was already corrected in commit b2c15b0.
Files fixed:
hooks/useOrgSettings.tsline 157: ChangedsetOrgData(data.data)tosetOrgData(data.account)hooks/useUser.tsxline 88: ChangedsetUserData(data.data)tosetUserData(data.account)in PATCH handlerhooks/useUser.tsxlines 141-150: Changed alldata.datareferences todata.accountin POST handler for account initialization
Summary
/api/account,/api/account/update, and/api/account/add_artistendpoints from Recoup-ChatuseUser.tsxto call Recoup-API'sPOST /api/accountsandPATCH /api/accountsendpointsuseOrgSettings.tsto call Recoup-API'sPATCH /api/accountsendpointChanges
POST /api/accountPOST https://recoup-api.vercel.app/api/accountsPOST /api/account/updatePATCH https://recoup-api.vercel.app/api/accountsGET /api/account/add_artistPOST https://recoup-api.vercel.app/api/accounts/artistsTest plan
pnpm buildto verify compilation🤖 Generated with Claude Code