Search code examples
ruby-on-railsrubydevise

why last sign in IP and current sign in IP Rails Devise not correct?


I am using rails occasionally, and first time using devise with trackable, and when i look into my table, the current_sign_in_ip and last_sign_in_ip are ::1 not my current ip, Cani know why? I already defined on user.rb model

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable, :confirmable, :trackable
end

Solution

  • For Devise to record your public ip, you need to expose your local server to the internet and access it from the outside. The easiest way to achieve that is using ngrok.

    Assuming your rails server is listening on the default port - 3000, you can generate a public URL using ngrok:

    $ ngrok http 3000
    

    And use that URL to access your Rails app and sign in. Devise will record your public ip as your current_sign_in_ip.