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

Receiving "You are already signed in" flash[:error] #58

Closed
sethtrain opened this issue Oct 24, 2019 · 14 comments
Closed

Receiving "You are already signed in" flash[:error] #58

sethtrain opened this issue Oct 24, 2019 · 14 comments
Assignees

Comments

@sethtrain
Copy link

After setting up devise and devise_masquerade all standard install from the documentation I get the flash[:error] result of "You are already signed in". I am running version 4.7.1 of devise and 1.2.0 of devise_masquerade.

If you look at the development log you will see Filter chain halted as :require_no_authentication rendered or redirected

Below is the log file in hopes that it helps with the issue:

Started GET "/users/masquerade/4?masquerade=u3g6hRnmVxjYhA4_yNZ0wA&masqueraded_resource_class=User" for 127.0.0.1 at 2019-10-23 23:45:16 -0500
Processing by Devise::MasqueradesController#show as HTML
  Parameters: {"masquerade"=>"u3g6hRnmVxjYhA4_yNZ0wA", "masqueraded_resource_class"=>"User", "id"=>"4"}
  User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?  [["id", 3], ["LIMIT", 1]]
  User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" IS NULL AND "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?  [["id", 4], ["LIMIT", 1]]
Redirected to http://localhost:3000/users/sign_in
Completed 302 Found in 4ms (ActiveRecord: 0.2ms | Allocations: 3177)


Started GET "/users/sign_in" for 127.0.0.1 at 2019-10-23 23:45:16 -0500
Processing by Devise::SessionsController#new as HTML
  User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?  [["id", 3], ["LIMIT", 1]]
Redirected to http://localhost:3000/
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 2ms (ActiveRecord: 0.1ms | Allocations: 1822)


Started GET "/" for 127.0.0.1 at 2019-10-23 23:45:16 -0500
Processing by HomeController#index as HTML
  Rendering home/index.html.erb within layouts/application
  User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?  [["id", 3], ["LIMIT", 1]]
  ↳ app/views/home/index.html.erb:4
  Rendered home/index.html.erb within layouts/application (Duration: 1.2ms | Allocations: 856)
Completed 200 OK in 8ms (Views: 6.9ms | ActiveRecord: 0.1ms | Allocations: 5501)

On redirect to HomeController there are some things that happen because I am able to successfully see a button that will reverse the masquerade so user_masquerade? seems to be working successfully. The back_masquerade_path also works as you would expect.

On the views the current_user isn't the user I expect it to be as it is the user logged in before masquerading.

@oivoodoo
Copy link
Owner

Hi @sethtrain .

Could you give a try and set Devise.masquerade_bypass_warden_callback=true?

Thank you!

@oivoodoo oivoodoo self-assigned this Oct 24, 2019
@oivoodoo oivoodoo pinned this issue Oct 24, 2019
@sethtrain
Copy link
Author

Hi @oivoodoo

Unfortunately, this setting doesn't seem to fix the issue.

@sethtrain
Copy link
Author

sethtrain commented Oct 24, 2019

After doing some debugging on this in RubyMine I am seeing find_by_masquerade_key(params[Devise.masquerade_param]) in find_resource to be the problem. I don't know just yet why but that is the piece that seems to be returning and empty recordset.

@oivoodoo
Copy link
Owner

@sethtrain could you verify you expires_in settings? Now token has only 1.minute by default to click Login As from UI

@sethtrain
Copy link
Author

sethtrain commented Oct 24, 2019

@oivoodoo Yes, it is 1.minute

@oivoodoo
Copy link
Owner

@sethtrain need to run away for one hour. come back to give a try to review the code again. I would suggest for now to add pry inside of masquerade! and show action if you have time to debug otherwise I will review it. thank you!

@sethtrain
Copy link
Author

@oivoodoo Sure thing, I'm deep in the debugger at the moment so I will let you know what I find. Thank you for your help.

@sethtrain
Copy link
Author

sethtrain commented Oct 24, 2019

@oivoodoo I figured it out. I was running in development mode with config.action_controller.perform_caching = false and config.cache_store = :null_store. So the fix was to touch tmp/caching-dev.txt which would then allow for memory caching to work and all of the masquerade token stuff to store correctly.

@oivoodoo
Copy link
Owner

@sethtrain oh. it sounds great! thank you that you resolved the issue.

@sethtrain
Copy link
Author

@oivoodoo Thanks for sticking with me while I debugged it. I will now close the issue.

@oivoodoo oivoodoo unpinned this issue Oct 24, 2019
@garymh
Copy link

garymh commented Nov 7, 2019

I'm actually getting this too... Is there a way to fix it without enabling caching?

@sethtrain
Copy link
Author

@garymh I didn't find a way to do it without enabling caching.

@leastbad
Copy link
Contributor

@oivoodoo I love this library, and it's 99% of the way to "it just works" status.

Can you please add instruction in your README.md for devs to make sure development mode is being cached? I lost so much time debugging this issue and while I'm thrilled it was such an easy solve, the actual solution is anything but obvious and if people don't find this thread, it's basically impossible to achieve successful integration in development.

Developers can run rails dev:cache one time during project bootstrapping and never have to worry about this behaviour.

@oivoodoo
Copy link
Owner

Hey @pjforde1978 . I am a bit busy the last days, if you have some time I would really appreaciate to have the pull request to update README.md. Thank you!

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

No branches or pull requests

4 participants