devise_token_auth没有返回访问令牌



我有一个rails应用程序,它过去只使用vanilla rails前端和设备。我正试图将其更改为前端有角度的api服务器,为此,我决定使用devise_token_auth和ng令牌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

在我的应用程序.rb和中设置

protect_from_forgery with: :null_session

在我的application_controller.rb中,它们似乎是这类问题最常见的解决方案,但对我来说不起作用

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

最新更新