Hi i am using redux saga generator function. The purpose of this function is login the user, according to the type of user. Here i am checking if the user of any specific type then, according to that i am redirecting the user to the specific route
.My question is before dispatching this action yield put(loginSuccess(response))
, i want to store token in localstorage
,as i tried this way but storing is taking some time. How can i fix this problem, or there any way to use promises
here or any other better solution to fix this problem
function* login(obj) {
const res = yield call(login, obj)
if (res.data.token) {
localStorage.setItem('token', res.data.token)
yield put(Success(res))
if (res.data.isAdmin == true) {
history.push('/admin')
} else if (res.data.userType == 'student') {
history.push('/student')
}
} else {
yield put(Error(res.message))
}
}