-
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Add Email Change to Settings Page
Goal
Let users change their email address from the settings page.
Tasks
1. Database migration
- Add columns to users table:
pending_email,pending_email_token,pending_email_expires_at
2. Update types (src/types.ts)
- Add new fields to
Userinterface
3. Update repository (src/db/user.ts)
- Add
findByPendingEmailToken(token: string)method
4. Update form (src/routes/auth/settings.html)
- Change email display (line 51-52) from read-only div to text input
5. Update POST handler (src/routes/auth/auth.ts)
- Add
emailtoupdateNameValidationschema (rename toupdateSettingsValidation) - If
email !== req.user.email:- Check new email isn't already in use (
findByEmail) - Generate token via
context.helpers.generateToken() - Set expiry using
VERIFICATION_TOKEN_EXPIRY_MSconstant - Store
pending_email,pending_email_token,pending_email_expires_at - Send verification email to new address
- Check new email isn't already in use (
6. Add endpoint (GET /verify-email-change)
- Add
middleware.authRateLimitMiddleware - Accept
?token=xxxquery param - Find user by
pending_email_token - Check token hasn't expired
- Update
emailfield, clear pending fields - Destroy session (
req.session.destroy()) - Redirect to
/loginwith flash message
Reference
- Existing
/verify-emailendpoint (auth.ts:349) for verification pattern VERIFICATION_TOKEN_EXPIRY_MSconstant (auth.ts:9)
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request