devise_token_auth未返回访问令牌

时间:2017-02-01 17:50:27

标签: ruby-on-rails angularjs devise

我有一个rails应用程序,以前只使用vanilla rails前端和devise。我正在尝试将其更改为具有角度前端的api服务器,为此我决定使用devise_token_auth和ng-token-auth。

我可以使用它们进行正常登录,但当我尝试导航到任何其他页面时,Cookie将被删除。

我认为问题是devise_token_auth没有返回带有初始登录的访问令牌。

我已经

config.middleware.insert_before 0, "Rack::Cors" do
  allow do
    origins '*'   #note to self, tighten this up, this isnt secure enough
    resource '*',
    :headers => :any,
    :methods => [:get, :post, :delete, :put, :options, :head],
    :expose  => ['access-token', 'expiry', 'token-type', 'uid', 'client'],
    :max_age => 0
  end
end

在我的application.rb和

中设置
protect_from_forgery with: :null_session

在我的application_controller.rb中,这似乎是这类问题最常见的解决方案,但它们并不适合我

1 个答案:

答案 0 :(得分:0)

原来问题是由active_model_serializer引起的。在此处找到解决方案:https://github.com/lynndylanhurley/devise_token_auth/issues/600 ,将serialization_scope :view_context添加到我的application_controller.rb