掲示板実装
Some checks failed
CI / scan_ruby (push) Has been cancelled
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
CI / system-test (push) Has been cancelled

This commit is contained in:
2026-02-19 22:30:59 +09:00
parent f25fd6f802
commit bb9ec2df1d
38 changed files with 1711 additions and 13 deletions

View File

@@ -0,0 +1,4 @@
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end

View File

@@ -0,0 +1,37 @@
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
end
private
def find_verified_user
# セッションからuser_idを取得してUserを特定する
# 注: セッションストアの設定に依存するが、CookieStoreデフォルトを想定
if verified_user = User.find_by(id: session_user_id)
verified_user
else
reject_unauthorized_connection
end
end
def session_user_id
# RailsのセッションCookieからuser_idを復元する
# _dip_front_session は config/initializers/session_store.rb で設定されているキー名、またはデフォルトの _app_session
# ここでは汎用的に取得を試みる
session_key = Rails.application.config.session_options[:key]
encrypted_session = cookies.encrypted[session_key]
if encrypted_session && encrypted_session["user_id"]
encrypted_session["user_id"]
else
# デバッグ用: 認証失敗時はnilを返す
nil
end
end
end
end