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

Cannot switch to another user with sign_in method #5751

Open
jbwl opened this issue Jan 7, 2025 · 0 comments
Open

Cannot switch to another user with sign_in method #5751

jbwl opened this issue Jan 7, 2025 · 0 comments

Comments

@jbwl
Copy link

jbwl commented Jan 7, 2025

Environment

  • Ruby 3.3.6
  • Rails 7.2.2.1 (API-only)
  • Devise 4.9.4

Current behavior

puts current_user.id
1
@mike = User.find(2)
sign_in(@mike, store: false)
# also tried:
sign_in(@mike, event: :authorization, store: false)
# result: current_user stays the same
puts current_user.id
1

Will be even more helpful if you provide a sample application or a test case that reproduces the error.

Expected behavior

puts current_user.id
2

Also the current_sign_in and last_sign_in timestamps are not changed, so it seems like there is no sign in actually happening with sign_in

Maybe I am not understanding how this is supposed to work? I am trying to sign in a different user when there already is a current_user, e.g. switching the user for impersonating in the frontend app ("An admin user can impersonate a standard user"). The frontend app handles the logic, I just a way to sign_in a different user on an authenticated route, because that route must only be accessible for admins.
The downstream issue for me is that devise-jwt will not dispatch an Authorization header because Devise isn't signing in the user.

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

1 participant