Fix registration and cart authentication issues #404
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Registration and Cart Authentication Issues
Description
Fixed critical authentication bugs preventing account creation and cart functionality for logged-in users.
Issues Fixed
1. Account Creation Not Working
Problem: After filling registration form and clicking "Create Account", nothing happened - no success message, no redirection, and no error shown.
Root Cause:
truefor valid inputs, but error state expected empty stringsalert()instead of toast notificationsSolution:
alert()with proper toast error messages2. Cart "Login Required" for Logged-in Users
Problem: After successful login, adding items to cart still showed "Login Required" popup.
Root Cause:
Solution:
useStatestorageandauthChangeeventsauthChangeevent after login/registration3. Profile Showing Wrong Email
Problem: Profile page showed OAuth email instead of JWT account email.
Root Cause:
Solution:
/api/auth/meendpoint firstuserData.data.emailanduserData.data.username)Technical Changes
Files Modified
1.
client/src/components/Card/RegisterCard/RegisterCard.jsvalidateEmail()to return""instead oftruefor valid emailsvalidatePassword()to return""instead oftruefor valid passwordsalert()withtoast.error()for password mismatchusernameTouchedto useEffect dependenciesauthChangeevent dispatch after registration2.
client/src/components/Card/ItemCard/ItemCard.jsisAuthenticatedstate to track auth statususeEffectto listen for auth changesstorageandauthChangeevents3.
client/src/components/Authentication/Login/Login.jsauthChangeevent dispatch after successful login4.
client/src/components/Account/MyAccount/MyAccount.js/api/auth/meendpoint firstuserData.data.emailanduserData.data.usernameTesting Completed
Registration Flow
Cart Functionality
Profile Display
Before & After
Before:
After:
API Endpoints Used
POST /api/auth/register- Create new accountPOST /api/auth/login- User loginGET /api/auth/me- Fetch authenticated user dataGET /api/auth/check-username- Check username availabilityBreaking Changes
None - All changes are backwards compatible
Dependencies
No new dependencies added
#292