登录keystone时无效的CSRF

时间:2018-02-18 15:51:21

标签: keystonejs

我对编码完全不熟悉。我看了一下,但没有找到任何相关的东西。

登录 keystone 以查看 mongoDB 数据库时,收到错误消息:

  

出了点问题;请刷新浏览器并重试。

这样做没有用。也没有删除浏览器历史记录或尝试从另一个膝上型电脑。

查看浏览器中的javascript控制台,错误指出invalid csrf

我认为这是 keystone 文件夹中的相关源代码:

handleSubmit (e) {
        e.preventDefault();
        // If either password or mail are missing, show an error
        if (!this.state.email || !this.state.password) {
            return this.displayError('Please enter an email address and password to sign in.');
        }

        xhr({
            url: `${Keystone.adminPath}/api/session/signin`,
            method: 'post',
            json: {
                email: this.state.email,
                password: this.state.password,
            },
            headers: assign({}, Keystone.csrf.header),
        }, (err, resp, body) => {
            if (err || body && body.error) {
                return body.error === 'invalid csrf'
                    ? this.displayError('Something went wrong; please refresh your browser and try again.')
                    : this.displayError('The email and password you entered are not valid.');
            } else {
                // Redirect to where we came from or to the default admin path
                if (Keystone.redirect) {
                    top.location.href = Keystone.redirect;
                } else {
                    top.location.href = this.props.from ? this.props.from : Keystone.adminPath;
                }
            }
        });
    },

如何解决此问题/调试错误?谢谢你的帮助!

1 个答案:

答案 0 :(得分:1)

当会话关联失败时,通常会发生这种情况。您是否使用默认的内存中会话管理?也许,尝试使用数据库来维护会话状态。

如果您使用MongoDB,请尝试以下配置设置

'session store': 'mongo',

查看'会话商店' http://keystonejs.com/docs/configuration/#options-database下的部分了解更多详情。