Easily switch user without login, logout
When you are working, sometimes you don't waste your time to login/logout with email and password, or the site have error, but this error is only raised for specified user.
So, you can try using gem Switch User.
Install
Open your Gemfile and add:
gem "switch_user
Usage
In my project, I'm using gem sorcery for authentication. So, the next step, I need run command:
rails g switch_user:install
A copy of the configuration file will be copied to config/initializers/switch_user.rb
. And I'll configure with provider is sorcery.
config.provider = :sorcery
You can learn more options at link https://github.com/flyerhzm/switch_user#configuration
Next, I'll open my route and add a route:
SwitchUser::Application.routes.draw do
match 'switch_user' => 'switch_user#set_current_user'
end
Add the following code into your page, I'm using Slim
= switch_user_select
Done, now you can open local site to check.
Written by Vinh Nguyen Le
Related protips
1 Response
eh? ... Really? Please explain for me