mattyr / sidecloq

Recurring / Periodic / Scheduled / Cron job extension for Sidekiq
MIT License
88 stars 12 forks source link

Fix issue where the Rack session is invalid for rake web #39

Closed Fryguy closed 1 year ago

Fryguy commented 2 years ago

Without this, you will get an Internal Server Error stating:

Sidekiq::Web needs a valid Rack session for CSRF protection. If this is a Rails app,
make sure you mount Sidekiq::Web *inside* your application routes:

Rails.application.routes.draw do
  mount Sidekiq::Web => "/sidekiq"
  ....
end

If this is a Rails app in API mode, you need to enable sessions.

  https://guides.rubyonrails.org/api_app.html#using-session-middlewares

If this is a bare Rack app, use a session middleware before Sidekiq::Web:

  # first, use IRB to create a shared secret key for sessions and commit it
  require 'securerandom'; File.open(".session.key", "w") {|f| f.write(SecureRandom.hex(32)) }

  # now use the secret with a session cookie middleware
  use Rack::Session::Cookie, secret: File.read(".session.key"), same_site: true, max_age: 86400
  run Sidekiq::Web
Fryguy commented 2 years ago

Travis seems not to be working here, but if you merge https://github.com/mattyr/sidecloq/pull/40 I can rebase this on top to use GitHub Actions.

mattyr commented 1 year ago

i believe this is now fixed in main! thanks