LoginSignup
3
3

More than 5 years have passed since last update.

Easily switch user without login, logout

Posted at

When you are working, sometime 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 config 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.

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3