Building auto login for fast Rails development with Sorcery

Login as various users during development can become pretty annoying especially since it’s very difficult to remember all of the passwords across users or apps. If your app authentication happen to be built with Sorcery here’s is a very easy and straightforward way how to implement auto login.

First we need a new route:

Restricting to development environment is important security wise although there might be cases when you want to do auto login in different environment. Good option is also to go with an environment variable.

I am adding the autologin method to SessionsController to keep it together with other session actions:

The method is simple since the heavy lifting is done by auto_login method from Sorcery.

Finally we can add little HTML snipped next to our login form:

Here we generate a sign in link for every user in our development database. This would also make a nice helper.

Join the Conversation

2 Comments

Leave a comment

Your email address will not be published. Required fields are marked *