ActionController::InvalidAuthenticityToken in RegistrationsController#create

前端 未结 8 1476
后悔当初
后悔当初 2020-11-29 19:39

Hi I am using Devise for my user authentication suddenly my new user registration was not working.

this was error I am getting.

ActionController::In         


        
8条回答
  •  感动是毒
    2020-11-29 20:34

    Just spent the entire morning debugging this, so I thought I should share this here in case someone faces a similar issue when updating rails to 5.2 or 6.

    I had 2 problems

    1) Can't verify CSRF token authenticity.

    and, after added skipping verification,

    2) request would go through but user still wasn't logged in.

    I wasn’t caching in development

      if Rails.root.join('tmp', 'caching-dev.txt').exist?
        config.action_controller.perform_caching = true
        config.action_controller.enable_fragment_cache_logging = true
    
        config.cache_store = :memory_store
        config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{2.days.to_i}" }
      else
        config.action_controller.perform_caching = false
    
        config.cache_store = :null_store
      end
    

    And in session_store

    config.session_store :cache_store,  servers: ... 
    
    
    

    I guess app was trying to store session in cache, but it was null - so it wasn’t logging in. 

after I ran

    bin/rails dev:cache
    

    which started caching - login started to work.

    You may need to

    • Rotate master.key
    • Rotate credentials.yml.enc
    • remove secrets.yml

提交回复
热议问题