Automatically log in on merb-auth account creation

Recently I was adding new user registration to and I wanted my users to be automatically logged in as soon as they created their account. I’m using merb for, and consequently merb-auth for authentication. It turns out it’s really easy to implement, but it took me a while to get it right. All you need to do is add the following to your action that creates the new user:

session.user = @user

That’s it. All you must do is set the user in the session to the newly created user. I hope this saves somebody else some time.

Brandon Dimcheff
Chief Architect

Brandon Dimcheff is a software engineer born and raised in Ann Arbor, Michigan. He uses go for his day job, has fallen in love with Kubernetes, is an aspiring functional programming language nerd, and is an advocate of open source.

comments powered by Disqus