Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Devise login after sign up

I'm using Devise to implement user signup/login. I want the user to be able to login automatically after a successful sign up. How can I do that. It might be the case that Devise this by default, but then maybe I disabled that setting somewhere. I can't remember...

like image 372
alpaca Avatar asked Oct 17 '25 07:10

alpaca


2 Answers

You have to:

1) Register the user into the website for devise. 2) Login the user.

For option 1, you can do something like:

if @user.save
  sign_in(@user)   
end

redirect_to after_sign_in_path(@user)

The things to have in mind, the first line tries to find for the user, on the second line, if it cannot find the user, it creates the user right away, then it sign_in the user, and finally redirect the user to where he should go after the login.

like image 187
Bharat soni Avatar answered Oct 20 '25 01:10

Bharat soni


I think you have enabled the Devise Confirmable module in your Devise setup.

If that is the case, you can either remove the confirmable module or you can allow users to have unconfirmed access for a specific period.

In your config/initializers/devise.rb:

config.allow_unconfirmed_access_for = 2.days
like image 44
webster Avatar answered Oct 20 '25 02:10

webster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!