为什么通用cookie不设置cookie?

时间:2019-05-27 16:05:56

标签: javascript reactjs cookies

我正在尝试使用客户端上的软件包Universal-cookie设置httpOnly cookie。我执行以下操作,但未设置Cookie:

import Cookies from 'universal-cookie';

const cookies = new Cookies();

export function signInUser({ email, password, history }) {
  return function(dispatch) {
    return api.post('/auth/sign-in', { email, password })
      .then(response => {
        const decoded = jwtDecode(response.data.token);
        const { roles, email, userId } = decoded;
        cookies.set('token', response.data.token, { path: '/', httpOnly: true });
        dispatch({ type: AUTH_USER, payload: { roles, email } });
        localStorage.setItem('user', JSON.stringify({ user: { roles, email, userId } }));
        history.push('/');
      })
  }
}

我在做什么错了?

0 个答案:

没有答案