From 955ee49ada9e4bf76e012162b94ba53b403fba31 Mon Sep 17 00:00:00 2001 From: Atul Tameshwari Date: Mon, 22 Jun 2026 13:03:29 +0530 Subject: [PATCH] fix(user): clone user data before updates to prevent mutations Updated the `updateCurrentUser` method in `UserStore` to clone the current user data before making updates, ensuring that the original data remains unchanged during the update process. Additionally, added logic to update the local state with the new user data after a successful update. fix(cover-image): return absolute URLs for cover images Modified the `handleCoverImageChange` function to return absolute URLs for cover images, ensuring compatibility with the expected format. This change includes handling both uploaded images and new images, providing a consistent return structure. --- apps/web/core/store/user/index.ts | 10 +++++++++- apps/web/helpers/cover-image.helper.ts | 8 +++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/web/core/store/user/index.ts b/apps/web/core/store/user/index.ts index 7181a6ed17f..5218c2ba9dd 100644 --- a/apps/web/core/store/user/index.ts +++ b/apps/web/core/store/user/index.ts @@ -153,7 +153,7 @@ export class UserStore implements IUserStore { * @returns {Promise} */ updateCurrentUser = async (data: Partial): Promise => { - const currentUserData = this.data; + const currentUserData = cloneDeep(this.data); try { if (currentUserData) { Object.keys(data).forEach((key: string) => { @@ -162,6 +162,14 @@ export class UserStore implements IUserStore { }); } const user = await this.userService.updateUser(data); + if (user && this.data) { + runInAction(() => { + Object.keys(user).forEach((key: string) => { + const userKey: keyof IUser = key as keyof IUser; + if (this.data) set(this.data, userKey, user[userKey]); + }); + }); + } return user; } catch (error) { if (currentUserData) { diff --git a/apps/web/helpers/cover-image.helper.ts b/apps/web/helpers/cover-image.helper.ts index 6ef7b2854c5..ebb5c19f8f8 100644 --- a/apps/web/helpers/cover-image.helper.ts +++ b/apps/web/helpers/cover-image.helper.ts @@ -272,11 +272,13 @@ export const handleCoverImageChange = async ( } if (analysis.needsUpload) { - await uploadCoverImage(newImage, uploadConfig); - return; + const assetUrl = await uploadCoverImage(newImage, uploadConfig); + // cover_image requires an absolute URL; cover_image_url is relative (matches GET /api/users/me/ format) + return { cover_image: getFileURL(assetUrl) || assetUrl, cover_image_url: assetUrl }; } - return { cover_image: newImage }; + // cover_image requires an absolute URL; getFileURL converts relative paths from the Upload tab + return { cover_image: getFileURL(newImage) || newImage, cover_image_url: newImage }; }; /**