Fast User Switcher for Developers

As pointed out below, you don’t actually need a plugin to easily switch users in development:

That said, this plugin might still be useful if you want easy links to switch accounts quickly.


When developing Discourse, I often find it’s useful to switch between user accounts. My general workflow currently looks something like this:

  • Open incognito window
  • Login using the admin account credentials that I remember (most of the time)
  • Hamburger
  • Admin
  • Users
  • Pick a user
  • Impersonate

If I want to change to another user, or inevitably close the incognito window by accident, I repeat that process again. Gets tedious very quickly.

When experimenting with various chat systems for discourse-chat-integration, I installed the development version of Zulip. I really liked the way they handle authentication when running in development mode: you just click a username and you’re in!

So, stealing that concept, this plugin replicates that functionality in Discourse. It adds a box to the footer, containing a list of every user (max. 50) on your development instance. All you do to login is click the username :tada:. The implementation is identical to the admin “impersonate” feature, but without all the safety features.

The footer is visible on every page, so you can switch users without even logging out!

52

The repository is available at https://github.com/davidtaylorhq/discourse-dev-login

12 Likes

You could add a guard that only activates the plugin in development mode.

10 Likes

Good idea, done. I’ll tone the warnings down a little now :wink:

5 Likes

Why not just use multiple browser profiles for this? Then you can hold (x) unique cookies per (x) browser profiles.

1 Like

I find this easier than switching between 5-6+ different browser profiles all the time ¯\_(ツ)_/¯. This means I can just have a single browser tab which I can use for testing every user.

As a middle way between one tab for multiple users, and one profile per user, I find Firefox Containers incredibly helpful, allowing me to have multiple tabs open, in the same profile/window, but logged in as separate users.

4 Likes

There is already a hidden feature to switch users quickly by URL that you could leverage.

In development mode, visit session/USERNAME/become with a GET request and you will impersonate that user. So you could adjust your plugin to just link to that GET route instead.

8 Likes

:facepalm: So basically I’ve just reimplemented something that already existed. :rofl:

Are there any other useful super-ninja features for development? Would be great to document this kind of stuff somewhere.

2 Likes

We should close this topic and put a warning at the top about that GET command for development.

1 Like

I’ve added a note at the top. I still think this plugin is vaguely useful, even if it wasn’t worth the development effort :wink:

3 Likes