angular - 如何使用 ngx-cookie-service for Angular 在我的 cookie 中设置安全标志?
问题描述
当我创建它时,我想在我的 cookie 中设置安全标志。我想我有解决方案,但我想确定以继续。我使用ngx-cookie-service来设置我的 cookie。
这是我的代码:
const now = new Date();
now.setHours(now.getHours() + 8);
const secureFlag = true;
this.cookieService.set('usertype', 'agent', now, '/', '/', secureFlag);
问题是我不知道是否必须像这样声明第 4 和第 5 个参数,因为如果我不声明它们会显示错误。
例如我试试这个:
const now = new Date();
now.setHours(now.getHours() + 8);
const secureFlag = true;
this.cookieService.set('usertype', 'agent', now, secureFlag);
它警告我Argument of type 'true' is not assignable to parameter of type 'string'
当我不想定义它们时,是否必须使用'/'
forpath
和参数?domain
解决方案
SameSite
这将起作用,如果您在使用 Google Chrome 时遇到问题,也可以在 Google Chrome 上测试默认禁用cookie。
将此粘贴到您的浏览器中,它将带您进入 SameSite 设置并禁用。
chrome://flags/#same-site-by-default-cookies
this.cookieService.set('sessionuser', username, 1 , '/', 'localhost', false, "Lax" );
推荐阅读
- javascript - 无法使我的 Javascript 代码工作以禁用加载页面上的输入框
- css - 管理面板的 Wordpress 样式
- javascript - 在 Javascript 和 nodejs 中使用从同一 module.exports 调用其他函数的异步函数
- node.js - DynamoDB AWS 没有取回任何数据,也没有错误
- r - ggplot2 轴刻度总是以科学数字出现。我该如何改变它
- r - 如果索引值接近另一个 df 中的索引,有没有办法从 df 中提取数据?
- kubernetes - 无法访问在 RPI 上运行的 K8 集群中的 NGINX nodePort 服务
- c# - 如何获取网址?
- javascript - 在 Nodejs 中使用 Lua 脚本的 Redis mget
- awk - 如何使用 AWK 从文件中读取并输出到 html 表