1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【エラー解決方法】Rails7:ActionDispatch::Request::Session::DisabledSessionError

Posted at

概要

  • https://qiita.com/kazama1209/items/caa387bb857194759dc5
    上記の記事でログイン機能を作成したのですが、ログイン画面からユーザーを「ID」と「パスワード」により認証するパスワード認証はできたのですが、リロードした際のトークン認証がうまくいきませんでした。

エラー内容

api_1    | app/controllers/api/v1/auth/sessions_controller.rb:3:in `index'
api_1    | Completed 500 Internal Server Error in 19ms (ActiveRecord: 2.7ms | Allocations: 684)
api_1    | 
api_1    | 
api_1    |   
api_1    | ActionDispatch::Request::Session::DisabledSessionError (Your application has sessions disabled. To write to the session you must first configure a session store):

解決方法

参考記事

解決手順

  • appフォルダ配下(controllerやmodelと同階層)にhelpersフォルダの作成
  • helpersフォルダ配下にrack_session_fix_controller.rbファイルの作成
  • 下記をrack_session_fix_controller.rbに記述
rack_session_fix_controller.rb
module RackSessionFixController
  extend ActiveSupport::Concern

  class FakeRackSession < Hash
    def enabled?
      false
    end
  end

  included do
    before_action :set_fake_rack_session_for_devise
    
    private

    def set_fake_rack_session_for_devise
      request.env['rack.session'] ||= FakeRackSession.new
    end
  end
end
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?