未设置Cookie

时间:2019-07-03 23:41:18

标签: node.js reactjs express express-session

我正在使用快速会话来生成会话,并且cookie是在邮递员中设置的,但是它们没有出现在chrome开发工具的“应用程序”标签中。

这是我的cookie配置,为了进行开发,安全性设置为false

  name: "config",
  secret: sessionSecret,
  cookie: {
    maxAge: 1000 * 60,
    secure: false,
    httpOnly: false
  },
  resave: false,
  saveUninitialized: false
};

这就是我订购全球中间件的方式

server.use(express.json());
server.use(session(sessionConfig));
server.use(cors());
server.use(morgan("combined"));
server.use("/api", Router);

我的React App.js及其调用的函数上的useEffect

  useEffect(() => {
    getAuthenticationStatus().then(() =>
      authenticated ? null : history.push("/")
    );
  }, []);

  const getAuthenticationStatus = async () => {
    await authenticateSession();
  };

useEffect内部的函数正在调用的函数

export const authenticateSession = () => dispatch => {
  dispatch({
    type: AUTHENTICATION_IN_PROGRESS
  });
  return axios
    .get(`${endpoint}/api/auth/authenticate`)
    .then(res => {
      console.log(res);
      dispatch({
        type: AUTHENTICATION_SUCCESS
      });
    })
    .catch(error => {
      console.log("error: ", error);
      dispatch({
        type: AUTHENTICATION_FAILURE
      });
    });
};

我对为什么未设置cookie感到茫然

0 个答案:

没有答案
相关问题