Open
Description
In the after_action I get an error, where the cookie is null:
require_relative "inertia_rails"
require_relative "helper"
module InertiaRails
module Controller
extend ActiveSupport::Concern
included do
before_action do
# :inertia_errors are deleted from the session by the middleware
InertiaRails.share(errors: session[:inertia_errors]) if session[:inertia_errors].present?
end
helper ::InertiaRails::Helper
after_action do
cookies['XSRF-TOKEN'] = form_authenticity_token unless request.inertia? || !protect_against_forgery?
end
end
cookies['XSRF-TOKEN'] = form_authenticity_token unless request.inertia? || !protect_against_forgery?
Resulting in this error
undefined method `[]=' for nil:NilClass
Activity
PedroAugustoRamalhoDuarte commentedon Dec 16, 2023
Hello @EamonIndigoSpark, can you share your ApplicationController? Maybe cookies it not defined because you are not using cookies rails middleware
EamonIndigoSpark commentedon Dec 18, 2023
Hi @PedroAugustoRamalhoDuarte
Thank you for your help, below is the contents of the controller I am using
`require "will_paginate/array"
class Cms::ApplicationController < ActionController::Base
protect_from_forgery
layout :set_layout
before_action :authenticate
before_action :set_site
before_action :set_current_org
before_action :show_current_org_logo
before_action :set_cms_for_menu
before_action :check_user_disabled
cache_sweeper :user_stamp_sweeper
VALID_CMS_HOSTNAMES = ['conferencestop']
def set_current_org
if user_signed_in? && (current_user.is_a_client? || current_user.is_a_supplier?)
if current_user.contact.present?
@current_org = current_user.contact.parent
end
if @current_org.blank? && !current_user.is_a_supplier?
flash[:alert] = "Sorry we could not find your organisation. Please contact Servace"
redirect_to destroy_user_session_path()
end
end
end
def authenticate
return true if (ENV["APP_NAME"] =~ /pentest/ ) != nil # don't need this when pentesting
end
def set_cms_for_menu
@cms = true
end
def set_layout
'integrated_layout'
end
def hide_main_nav
@hide_main_nav = true
end
private
end
`
PedroAugustoRamalhoDuarte commentedon Dec 18, 2023
@EamonIndigoSpark You accidentally share your app password.
PedroAugustoRamalhoDuarte commentedon Dec 18, 2023
Your ApplicationController looks right its a very strange error, things you can check:
For now you can downgrade de inertia rails version to: 3.0.0, this was the last update without XSRF-TOKEN update
EamonIndigoSpark commentedon Dec 18, 2023
@PedroAugustoRamalhoDuarte Hi Pedro,
Thank you for your help, I will try the things you suggest, also I've removed the password (fortunately, it is only available internally)