Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

How to broadcast without logged in user #207

Closed
zben opened this issue Jan 28, 2024 · 0 comments
Closed

How to broadcast without logged in user #207

zben opened this issue Jan 28, 2024 · 0 comments

Comments

@zben
Copy link

zben commented Jan 28, 2024

I think current logic assumes there is current user before broadcast can happen. I had to do fake a user record with an arbitrarily large id to make broadcast work. What I am trying to do is to have light feature that user without logging in can try with assigned session_uuid in the browser session. Because I always subscribe to an actual AR object with different id and there is already encryption of channel name, there is no risk of them seeing each other's data.

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    include SetCurrentRequestDetails

    identified_by :current_user, :current_account, :true_user
    impersonates :user

    delegate :params, :session, to: :request

    def connect
      self.current_user = find_verified_user
      set_request_details
      self.current_account = Current.account || Account.new(id: 10000000000)

      logger.add_tags "ActionCable", "User #{current_user.id}", "Account #{current_account.id}"
    end

    protected

    def find_verified_user
      if (current_user = env["warden"].user(:user))
        current_user
      else
        User.new(id: 1000000000)
        # reject_unauthorized_connection
      end
    end

is there a more elegant way on the framework level to handle this?

Repository owner locked and limited conversation to collaborators Jan 28, 2024
@excid3 excid3 converted this issue into discussion #208 Jan 28, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant