簡體   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