PIX-93: change username in profileview#102
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements functionality to allow users to change their username from the profile view. The implementation adds a new API endpoint for updating usernames, with proper authentication and validation, and updates the frontend to provide an inline editing experience.
Changes:
- Added backend API endpoint for updating user profiles with authentication and validation
- Implemented frontend username editing UI with edit/save/cancel controls
- Updated user store to persist username changes and refresh authentication token
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| server/src/services/user.service.ts | Added updateUser method to handle username updates with validation and token regeneration |
| server/src/routes/api.ts | Added PUT endpoint for user profile updates |
| server/src/controllers/user.controller.ts | Added update controller with authorization and input validation |
| client/src/views/ProfileView.vue | Added inline username editing UI with edit/save/cancel functionality |
| client/src/stores/user.store.ts | Added updateProfile function to update username and persist changes |
| client/src/services/api.ts | Added updateUser API function |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| localStorage.setItem("authToken", authToken) | ||
| localStorage.setItem("userId", userId) | ||
| localStorage.setItem("isAdmin", String(admin)) | ||
| localStorage.setItem("isAdmin", String(admin)) |
There was a problem hiding this comment.
Duplicate localStorage.setItem call for 'isAdmin'. The second call on line 19 should be removed as it's redundant.
| localStorage.setItem("isAdmin", String(admin)) |
| throw new Error("User not found") | ||
| } | ||
|
|
||
| const token = jwt.sign({ id: user._id, username: user.username, isAdmin: user.isAdmin }, JWT_SECRET, { expiresIn: CONFIG.JWT.EXPIRES_IN as any }) |
There was a problem hiding this comment.
This JWT token generation logic is duplicated from the login method. Consider extracting it into a private helper method to improve maintainability and reduce code duplication.
| const userStore = useUserStore(); | ||
| const notificationStore = useInAppNotificationStore(); | ||
| const { isMuted } = storeToRefs(notificationStore); | ||
| import { useToastStore } from '../stores/toast.store'; // Assuming toast store exists per api.ts file earlier |
There was a problem hiding this comment.
The comment 'Assuming toast store exists per api.ts file earlier' is unclear and seems out of place. If the toast store is a standard part of the codebase, this comment should be removed or clarified.
| import { useToastStore } from '../stores/toast.store'; // Assuming toast store exists per api.ts file earlier | |
| import { useToastStore } from '../stores/toast.store'; |
| // Error is handled globally usually, but specific UI feedback here is good | ||
| console.error("Failed to update username", error); |
There was a problem hiding this comment.
This comment suggests that error handling exists globally, but no toast error message is shown in the catch block. Either remove the comment or add appropriate user feedback for errors.
| // Error is handled globally usually, but specific UI feedback here is good | |
| console.error("Failed to update username", error); | |
| console.error("Failed to update username", error); | |
| toastStore.add('Failed to update username. Please try again.', 'error'); |
No description provided.