bradtraversy / proshop_mern

Shopping cart built with MERN & Redux
1.99k stars 1.18k forks source link

user name not updating in header on user update profile #21

Closed charmander-x closed 3 years ago

charmander-x commented 3 years ago

username is not being updated when i update user details i tried different things but nothing works. please tell what to do

basir commented 3 years ago

check if you update redux store after signin and you use it in app.js to show userInfo in the navbar.

AtharvRedij commented 3 years ago

This is because we have userInfo in 3 different reducers. userLoginReducer userRegisterReducer userUpdateProfileReducer

When you update profile userUpdateProfileReducer updates it's userInfo. But your Header is connected to userLoginReducer which still has old data.

charmander-x commented 3 years ago

so basically how can i do it -- some code will be helpful

AtharvRedij commented 3 years ago

I faced a similar issue regarding registration https://github.com/bradtraversy/proshop_mern/issues/19

I haven't yet written the code to fix this problem. But you will probably need to have a single userInfo object in store that all three reducers are connected. That will solve this issue. This will require a lot of changes to redux actions & reducers

charmander-x commented 3 years ago

please post it here when you do so

charmander-x commented 3 years ago

i found the fix that's probably not the correct way but its working good 😃

in user actions after USER_UPDATE_PROFILE_SUCCESS put another dispatch({ type: USER_LOGIN_SUCCESS, payload: data, }); localStorage.setItem("userInfo", JSON.stringify(data));

so basically it'll set userInfo to the udpated values

bradtraversy commented 3 years ago

Check the latest commits. I am adding a new video to the course now explaining. It will be the last video in the Frontend Authentication section