Я пытаюсь получить cookie, который я сохраняю (httpOnly), когда пользователь входит в систему. Проблема возникает, когда я восстанавливаю этот cookie со стороны сервера;Я посылаю его, чтобы отреагировать и сохранить в редукторе, но в процессе обновления маршрутизатора похоже, что пользователь не вошел в систему. Какие-либо решения?
Обновление:
экспресс-код:
let token = jwt.sign({
id: usuario.dataValues.id,
identifier: response.dataValues.email,
firma: firma
}, 'privatekey', (err, tk) => {
if (err) { console.log(err) }
let caducidad = 4 * 24 * 3600 * 1000;
const options = {
httpOnly: true,
signed: true,
maxAge: caducidad,
expires: new Date(Date.now() + caducidad)
};
res.cookie('token', tk, options).status(200);
res.status(200).json({ success: true, tk, user: response.dataValues })
})
Реактивная выборка:
export const getCookie = async () => {
await axios.post('/api/getCookie')
.then(res => {
if(res.data.token && res.data.token !== undefined) {
const user:User = jwtDecode(res.data.token);
axios.post('/api/comprobarFirma', {id: user.id, firma: user.firma})
.then(response => {
if (response.data.find) {
dispatch({type: 'setUser', payload: user});
console.log(user);
}else{
destroyCookie();
}
})
}else{
destroyCookie();
}
});
};