【问题标题】:Logging out returns Can't verify CSRF token authenticity注销返回 Can't verify CSRF token 真实性
【发布时间】:2021-07-27 22:30:37
【问题描述】:

我大部分时间都可以登录和注销,但有时在注销过程中,我会返回如下所示的错误,并且我没有注销。

Can't verify CSRF token authenticity.
User excluded error: #<ActionController::InvalidAuthenticityToken: ActionController::InvalidAuthenticityToken>

我无法注销并不总是发生,但是当我无法在上面注销时是我得到的错误。我读到了这就是我到目前为止所做的。我在前端使用 vuejs,在后端使用 rails。我正在使用 Rails 5.1 版。

application_controller.rb

protect_from_forgery with: :exception

application.html.erb

<%= csrf_meta_tags %>

这是我为注销用户而发出的 axios 请求

index.vue

logout() {
 this.$axios.delete('/users/sign_out').then(function(response) {
  console.log("Logged out")
 });
}

请帮我解决这个问题

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-5 csrf


    【解决方案1】:

    您可能需要将 csrf_meta_tags 添加到请求中

    在您的情况下,application.html.erb 中的 csrf_meta_tags 不会重新渲染。

    【讨论】:

    猜你喜欢
    • 2013-02-20
    • 2016-02-27
    • 2019-01-21
    • 2016-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-25
    相关资源
    最近更新 更多