1

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?

Ben Aubin
  • 5,542
  • 2
  • 34
  • 54

1 Answers1

0

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.

UPDATE

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

  def skip_confirmation!
    self.confirmed_at = Time.now.utc
  end

  def confirmed?
    !!confirmed_at
  end

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

Greg Answer
  • 717
  • 5
  • 15