bradtraversy / mern-tutorial

Goalsetter application from Youtube series

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing Early Return in Dashboard.jsx hangs redirection to /Login on Logout

AlexDarigan opened this issue · comments

In Dashboard.jsx at line 24 where the user is being navigated to the login page on null user ( likely due to logout being pressed ), there is an early return that is missing. Without that return, a user would have to click logout and also refresh the page to reach login.

( I'm a newbie to react so maybe there is a more conventional react way of doing this ).

In the Dashboard make sure you are importing { reset } from the authSlice not goalSlice

I am also having the same error. when logout is pressed the local storage is cleared and both the logout and reset actions are being called. but the problem is on the authSlice page I think as we made a await statement when authService.logout() is called but on my IDE it shows await is not necessary as logout is not returning any promise (just removing the localStorage) ,
const handle logout = (e) => {
dispatch(logout())
dispatch(reset())
navigate('/') // this gets called before both dispatches
}

so its redirecting before dispatching both actions

Can anyone help me?