繁体   English   中英

Cookie 安全且 httpOnly 使用 React 和 Cookie-Storage

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM