devise sign up automatically signs in user

2019-08-01 10:28发布

问题:

when i sign up a user, but don't have confirmable setup just yet (i.e. will be in the future but commented out for now), does it automatically sign in the user?

i need sign_up to just sign_up the user, but not sign him in, it needs to redirect to the login page, how do i get sign up to not log the user in?

回答1:

Instead of copy pasting code and replacing one line (which could be harder to maintain), just override the after_sign_up_path_for(resource), so it uses the after_sign_in_path_for(resource) instead:

def after_sign_up_path_for(resource)
    after_sign_in_path_for(resource)
end


回答2:

You need allow unconfirmed user to access at least one day.

In your config/initializers/devise.rb:

config.allow_unconfirmed_access_for = 1.days


回答3:

Override the RegistrationsController and then override the create action. Then replace this line in your new create action. Don't forget to use the rest of the code from the original create action.