小编Ami*_*far的帖子

res.clearCookie 函数不会删除 cookie

我正在为我的 express(带有打字稿)应用程序创建一个授权系统,我使用 JWT 并将它们保存到 cookie 中以保持用户登录。我的注销部分有问题, res.clearCookie() 不会删除 cookie。

我在索引文件中使用了 cookie-parser,并尝试使用空值或现在的到期日期重置 cookie,但它对我不起作用。正如我上面所说, res.clearCookie("jwt") 也不起作用。所有依赖项都是最新的。

登录和登录验证工作正常,我可以正确设置和读取 [和解码] JWT。

登录代码的主要部分

res.cookie("jwt", token, {
   httpOnly: true,
   expires: new Date(
       Date.now() + 1000 * 86400 * stayLoggedInDays
   )
}).send("Message: Login successful");
Run Code Online (Sandbox Code Playgroud)

登出代码

router.post(
  "/logout",
  (req, res, next) => {
    res.clearCookie("jwt");
    next();
  },
  (req, res) => {
    console.log(req.cookies);
    res.end("finish");  
  }
);
Run Code Online (Sandbox Code Playgroud)

注销后,我仍然可以看到用户个人资料,但是如果我从邮递员那里手动删除 cookie,个人资料页面将不会显示任何信息,所以我的结论是 express 无法清除 cookie。

javascript cookies node.js express typescript

5
推荐指数
1
解决办法
2669
查看次数

sequelize.sync():NUMBER 附近的 SQL 语法错误

我使用 制作了 4 个 Sequelize 模型sequelize.define();。模型几乎是相同的东西,但表名不同。因为我不想在 MySQL cli 上手动创建它们,所以我决定在我的主 index.js 文件中使用 Sequelize.sync() 来让 Sequelize 创建表,但是当我运行应用程序时,它遇到了错误Unhandled rejection SequelizeDatabaseError: You have an error in your SQL syntax;并且没有'不做桌子。

我已经尝试过这两种sequelize.sync();方法sequelize.sync({ force: true }); ,也尝试过一一同步模型,但出现了相同的错误!

我的模特之一

export const Product = sequelize.define(
  "product",
  {
    doInMyPlace: { type: Sequelize.BOOLEAN, allowNull: false },
    address: { type: Sequelize.STRING, allowNull: false },
    mapAddress: { type: Sequelize.STRING, allowNull: false },
    date: { type: Sequelize.STRING, allowNull: false },
    time: { type: Sequelize.STRING, allowNull: false }, …
Run Code Online (Sandbox Code Playgroud)

javascript mysql node.js sequelize.js typescript

3
推荐指数
1
解决办法
5941
查看次数