feat: add user profile editing with email re-verification
Backend changes: - Add PATCH /api/users/me endpoint for profile updates (firstName, lastName, email) - Add PATCH /api/users/me/password endpoint for password change - Email change triggers re-verification flow (emailVerified=false, new verification token/code) - Send verification email automatically on email change - Return new JWT token when email changes (to update emailVerified status) - Add validation for profile update and password change - Create user controller with updateProfile and changePassword functions Frontend changes: - Add ProfilePage with tabbed interface (Profile & Password tabs) - Profile tab: Edit firstName, lastName, email - Password tab: Change password (requires current password) - Add Profile link to navigation bar - Add authAPI.updateProfile() and authAPI.changePassword() functions - Update AuthContext user data when profile is updated - Display success/error messages for profile and password updates Security: - Username cannot be changed (permanent identifier) - Email uniqueness validation - Password change requires current password - Email change forces re-verification to prevent hijacking User flow: 1. User edits profile and changes email 2. Backend sets emailVerified=false and generates new verification tokens 3. Verification email sent to new address 4. User must verify new email to access all features 5. Banner appears until email is verified
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
const express = require('express');
|
||||
const { authenticate } = require('../middleware/auth');
|
||||
const { prisma } = require('../utils/db');
|
||||
const { updateProfile, changePassword } = require('../controllers/user');
|
||||
const { updateProfileValidation, changePasswordValidation } = require('../middleware/validators');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -64,4 +66,10 @@ router.get('/me', authenticate, async (req, res, next) => {
|
||||
}
|
||||
});
|
||||
|
||||
// PATCH /api/users/me - Update user profile
|
||||
router.patch('/me', authenticate, updateProfileValidation, updateProfile);
|
||||
|
||||
// PATCH /api/users/me/password - Change password
|
||||
router.patch('/me/password', authenticate, changePasswordValidation, changePassword);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user