Devise After first login redirect

Mini John

Normally after_sign_up_path would work but now that i have confirmations, this goes to the trash.

I'm searching for a way to redirect a user on his FIRST SIGN IN, meaning that

  • sign_in_count == 0

  • last_sign_in == nil

so i added to my applications_controller.rb

def after_sign_in_path_for(user)
  if current_user.sign_in_count == 0
    welcome_path
  end
end

but of course this didn't work. What am i missing ?

Richard Peck

After testing, we found Devise sets the value of sign_in_count immediately after login, meaning that it's never going to be 0, it's going to be 1 for a first-time login:

#config/routes.rb
devise_for :users, controllers: { sessions: "sessions" }

#app/controllers/sessions_controller.rb
class SessionController < Devise::DeviseController

    def after_sign_in_path_for(resource)
        if resource.sign_in_count == 1
           welcome_path
        else
           root_path
        end
    end

end

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related