Skip to content

Custom Session Data #11

@mrrooijen

Description

@mrrooijen

Hi,

Is it possible to access a user's session data from a route that's handling a websocket?

get "/room/:id" do |room_id|
  room = Room.find(room_id)
  user = User.find(session[:uid])

  if RoomConnAuthorizer.new(room, user).authorized?
    request.websocket do |ws|
      ws.onopen { publish(room, "#{user.name} connected.") }
      ws.onclose { publish(room, "#{user.name} disconnected.") }
    end
  else
    401
  end
end

Is something like this possible? How does one authorize connecting users? The session appears to contain some information, such as session_id, but none of the custom data (such as session[:uid]) that has been previously set.

Any help much appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions