[英]How can I create secure/httpOnly cookies with document.cookie?
[英]Cookies secure and httpOnly with React and Cookie-Storage
我正在尝试将安全和 httpOnly 放在我的 cookie 中,但它无法识别它:
import { CookieStorage } from 'cookie-storage';
const KEY_SECURE = 'cookie-secure';
const store = new CookieStorage({
httpOnly: true,
secure: true,
sameSite: 'strict',
});
export default class AuthToken {
static getToken() {
return JSON.parse(store.getItem(KEY_SECURE)) || null;
}
static setToken(token) {
if (token) {
store.setItem(KEY_SECURE, JSON.stringify(token));
AuthToken.setSesion();
} else {store.removeItem(KEY_SECURE);
AuthToken.removeSesion();
AuthToken.removeLastUserEvent();
}
}
我错过了什么?
出现问题是因为我在不安全的环境 HTTP 中执行它,在 HTTPS 中工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.