Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign in and out a user in Request type specs tuto not working anymore when integrating OmniAuth into Rails API #5105

Closed
YassineDM opened this issue Jul 31, 2019 · 2 comments

Comments

@YassineDM
Copy link

Environment

  • Ruby 2.6.2
  • Rails 6.0.0.rc2
  • Devise 4.6.2

Current behavior

Il followed proposed tuto to sign in and out a user in Request type specs and it worked fine. It introduces this sign_in method:

  def sign_in(resource)
    login_as(resource, scope: warden_scope(resource))
  end

But as I am trying integrating OmniAuth into a Rails API, I stumbled upon their section when they advise to add in application.rb:

config.session_store :cookie_store, key: '_interslice_session'
config.middleware.use ActionDispatch::Cookies # Required for all session management
config.middleware.use ActionDispatch::Session::CookieStore, config.session_options

This seems to be causing the sign_in method to fail with this error message:

undefined method `[]=' for nil:NilClass

Commenting config lines makes it work again...

Expected behavior

Ability to sign in user

@tegon
Copy link
Member

tegon commented Aug 1, 2019

Hello @YassineDM, thanks for your report.

The wiki is maintained by the community. So if there aren't any up to date instructions, we recommend you to explore the solution yourself and hopefully contribute your findings back.

You shouldn't need to define the sign_in method, using the Devise::Test::IntegrationHelpers module should be enough.

I'm going to close this issue since we reserve the issue tracker for problems in the library only. If you still need help, please open a question on Stack Overflow. You can even send it to me here and I'll try to help.

Thank you!

@tegon tegon closed this as completed Aug 1, 2019
@YassineDM
Copy link
Author

Hi @tegon, thank you for your answer.
I found a solution to my problem thanks to @mrstif in this issue. By the way, I noticed that you already exchanged with him on the matter...
Here is his answer for the record:

Apparently, in rails-api mode, the ActionDispatch::Cookies and ActionDispatch::Session::CookieStore middlewares are inserted in the end of the middleware stack, which doesn't occur in normal Rails mode.

Due to this, those middlewares are included after Warden::Manager which messes up something in request specs...

Therefore, this solved it:

Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Cookies
Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Session::CookieStore

Also, you're right, I didn't need to define the sign_in method, using the Devise::Test::IntegrationHelpers module was indeed enough. Thx again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants