Stefan Templin Stefan Templin - 1 year ago 91
Ruby Question

Setting a Time-Zone breaks Devise Authenthication

I'm using with and devise-token-auth.

I did this in my user model and it worked fine:

before_create :skip_confirmation!

# Include default devise modules.
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

I was able to create accounts, which got confirmed automatically.
For other stuff I needed to change the timezone of the application by adding the following to my application.rb.

config.time_zone = 'Europe/Berlin'
config.active_record.default_timezone = 'Europe/Berlin'

The time zone stuff works as well, but for unknown reasons, creating users stopped. If I create one and try to login, this error occurs:

A confirmation email was sent to your account at '...'. You must follow the instructions in the email before your account can be activated

In my database after creating an account with the new time zones every timestamp value for the user record was inserted correctly (using the new time zones).

How can I fix this?

Answer Source

I believe that for some reason the timezone Devise uses to set the confirmed_at field on the users table is ahead of the 'Europe/Berlin' time zone. So when Devise does the check to see if confirmed_at is set to a date/time before the current date/time, it returns false.

Solution: Try restarting your server to see if that updates it.


I took at look at Devise::Models and I see the following code:

  def skip_confirmation!
    self.confirmed_at =

  def confirmed?

This basically leads me to believe that it is best to set app times in UTC and later convert them using a Gem like Local Time