Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

devise first login with rails

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

like image 284
Jseb Avatar asked Dec 12 '25 13:12

Jseb


1 Answers

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 ) 
like image 168
sameera207 Avatar answered Dec 15 '25 13:12

sameera207



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!