user6538437
user6538437

Reputation:

InvalidAuthenticityToken in Devise

I recently added a piece of code to my ApplicationController to set the timezone of the current block to the one specified by the user.

class ApplicationController < ActionController::Base
  around_action :set_time_zone, if: :current_user
  protect_from_forgery with: :exception

  private

  def set_time_zone(&block)
    Time.use_zone(current_user.time_zone, &block)
  end
end

For some reason when I try to sign in i get a

ActionController::InvalidAuthenticityToken in Devise::SessionsController#create

If i remove

around_action :set_time_zone, if: :current_user

I can sign in and if i add it back after I sign in, everything works as expected.

Any ideas?

Upvotes: 1

Views: 2089

Answers (1)

jeremy6d
jeremy6d

Reputation: 108

This page has good info on the problem, but I was weirdly able to fix this in Rails 5 by putting protect_from_forgery above the around_action/filter. Hope it helps!

Upvotes: 4

Related Questions