1
votes

How can I determine on my custom session controller that the user is the first time login, I want to be able to create a session and to redirect to welcome#index if its the first time else it would be redirected to root_url.

The code that I have is has follow

class MysessionsController < Devise::SessionsController
  def create
    self.resource = warden.authenticate!(auth_options)
    set_flash_message(:notice, :signed_in) if is_navigational_format?
    sign_in(resource_name, resource)
    respond_with resource, :location => after_sign_in_path_for(resource)    
  end
  protected
  def after_sign_up_path_for(resource)
    "http://google.com"

  end 
end

I know I need to custom after_sign_up_path_for(resource) to what I want but I cant find how to determine if the user has sign in before or not with devise

1
after_sign_up_path_for determines what page the user is directed to after signing up, which will obviously be their first time logging in (since it is directly after signing up). - Logan Serman
So the code that i have works? - Jseb
You might have to move your after_sign_up_path_for to a custom registrations controller (instead of sessions). Or even move it to ApplicationController. - Logan Serman
I see thanks, this is helpful - Jseb
The problem i have is that i am using the confirmable module, so what i am thinking is to have my session with the two method but i dont think calling both of them is great any solution - Jseb

1 Answers

10
votes

you should be able to do this with :sign_in_count column. if this is 0 it means user has not sign in before

So as an example

redirect_to ((current_user.sign_in_count == 0) ? path1 : path2 )