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 . 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!
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.
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.