我在登录/注销时遇到问题,然后在表单中显示数据。如果我重新启动服务器并在不注销的情况下登录,它可以工作并显示数据。但是,如果我登录,然后注销,然后再次登录,似乎输入的数据花费的时间太长,并且不会显示在表单中。useEffect
这是我的登录名:
export const login = (email, password ) => async dispatch => {
const config = {
headers: {
'Content-Type':'application/json'
}
}
const body = JSON.stringify({email, password})
try{
const res = await axios.post('/api/auth/login', body, config)
dispatch({
type: LOGIN_SUCCESS,
payload: res.data
})
dispatch(loadUser())
} catch (e){
let errors = e.response.data;
console.log(errors)
if(errors) {
dispatch(setAlert(errors.message, 'danger'))
}
dispatch({
type: LOGIN_FAIL
})
}
}
这是我的注销:
export const logout = (history) => dispatch => {
dispatch ({ type: CLEAR_PROFILE })
dispatch ({ type: LOGOUT })
history.push('/proveedores')
}
这就是我获取数据的方式:
export const getCurrentProfile = () => async dispatch => {
try{
const res = await axios.get('/api/usuarios/me')
dispatch({
type: GET_PROFILE,
payload: res.data
})
} catch (e) {
dispatch({
type: PROFILE_ERROR,
payload: {msg: e.response.message}
})
}
}
我没有粘贴我的整个组件,因为它很多,但它只是重复输入。
我需要一种方法来修复注销后登录时丢失的数据。
紫衣仙女
九州编程
相关分类