-
Notifications
You must be signed in to change notification settings - Fork 109
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
Use "switch back" feature with links #55
Comments
Hi David, you've got a couple of choices.
If you want to use 2. The switch back feature is use by:
|
Is it correct that the only way to remember the original user is to make a distinct request ahead of switching? My use case is fairly straightforward in that I want to facilitate admins signing in as other users and then back again. Our user database has a few tens of thousands of records, so a dropdown doesn't work, and instead I am using a small form with a text field with user ID. However since I need to send a request to I've tried hacking around this. Ideally, I could switch users and remember the original user in a single request, e.g. |
I think what you might be missing is how we know whether to let you switch back or not. If you switch to a customer all I would know, without remembering that you were an admin before, is that you're a customer. We don't show customers the switch_user select box, so you're now locked out. |
I still don't understand why we can't (or wouldn't want to) remember the original user and switch users in a single request. |
You definitely could, I didn't realize that's what you were asking. The feature was added with a little haste, but I'm sure it could be refactored. |
Given my longwinded-ness, I probably didn't realize it was what I was asking either, heh. I just wanted to know if there was a security concern that prevented such an implementation. I will look into making such adjustments. |
I stumbled across the same issue and couldn't understand why there wasn't a single entry point remembering and switching. I already had a case where I wanted to pass the redirect path via the url so my redirect path already looked like this:
My link to become a user looks like this (in HAML):
The return path looks like this
Maybe this will help. Seems to work for me. Still wouldn't mind a more direct way of doing this. |
I agree with the others that a switch-back feature would be ideal. I don't care about the user being able to switch to a third user, just switching back to their original admin account. I tried implementing Helloenvoy's recommendation but ran into issues because I have a wildcard route that interferes with manually linking to the "/switch_user/remember_user" path. I could probably dig into the source code to figure out what controller action handles that and manually add a route, but for now I'll just force the admin to sign out and back in again. |
I added a patch that allows one to disable the default routes. I then just extended the default controller to handle a single request for remembering and switching. It seems to work. There's probably more elegant ways to get it done, but it works for me.
Lastly, to support the notion of 'switch back', I just overrode devise's sessions controller to sign in the original user upon destroy.
|
@jhenkens can you submit a pull request? |
@WojtekKruszewski The ability to disable the routes (and thus, allow you to definite your own routes, replacing the controller) was pulled in via PR with 6759686. Everything else I did that I detailed above was personal changes within the directory of my own application, not within the gem itself. |
Actually, only now I realized |
This issue brought me here and I got inspired by @WojtekKruszewski and ended up writing my own to work with devise. Here is my controller
Just check the session token in the view with erb if you should show the token. |
`#remember_user`. We need to be able to tell the gem that we want the user to be remembered so that we can switch back to it. It was unclear how it should've been done, so this is making sure that we don't have to make two calls to the `SwitchUser API`, just to make sure the original user will be remembered. Related Issue: flyerhzm/issues/55
Hello,
I don't want to use the
switch_user_select
(because we have too many users, and it does not fit the way we're doing things). Instead, I'm generating a switch user link, as described in the README:How can I enable the switch back feature, and allow a user to switch back to their previous login, if they used the link above to switch, in the first place?
Is there something I could do to save the original user, and then check if present, to allow switch back?
Thanks for your help,
David
The text was updated successfully, but these errors were encountered: