RailsEventStore / rails_event_store

A Ruby implementation of an Event Store based on Active Record
http://railseventstore.org
MIT License
1.4k stars 122 forks source link

InvalidAuthenticityToken #1752

Closed casiodk closed 4 months ago

casiodk commented 4 months ago

I have this setup in my ApplicationController

around_action :use_request_metadata
private

  def use_request_metadata(&block)
    Rails.configuration.event_store.with_metadata(request_metadata, &block)
  end

  def request_metadata
    {
      current_user_id: current_user&.id,
      current_admin_user_id: current_admin_user&.id,
      request_host: request.host
    }
  end

Then I added this line

protect_from_forgery with: :exception, unless: -> { request.format.json? }

which resulted in this error when signing in through a normal rails form

ActionController::InvalidAuthenticityToken in Admin::SessionsController#create

When i remove this line around_action :use_request_metadataeverything works as expected.

swistak35 commented 4 months ago

@casiodk Have you tried this? https://stackoverflow.com/a/44787573

casiodk commented 4 months ago

@casiodk Have you tried this? https://stackoverflow.com/a/44787573

That worked :) Thanks alot! @swistak35