Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for synchronize without authenticate of current_user #375

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
# * Requires Redis.
config.synchronize = false

# Change to true to enable synchronize without authentize
config.synchronize_without_auth = false

# Prevent Thin from daemonizing (default is true)
# config.daemonize = false

Expand Down
4 changes: 4 additions & 0 deletions lib/websocket-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def synchronize?
config.synchronize == true || config.standalone == true
end

def synchronize_without_auth?
config.synchronize == true and config.synchronize_without_auth == true
end

def standalone?
config.standalone == true
end
Expand Down
8 changes: 8 additions & 0 deletions lib/websocket_rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ def synchronize=(synchronize)
@synchronize = synchronize
end

def synchronize_without_auth
@sync_without_auth ||= false
end

def synchronize_without_auth=(synchronize_without_auth)
@sync_without_auth = synchronize_without_auth
end

def redis_options
@redis_options ||= redis_defaults
end
Expand Down
6 changes: 6 additions & 0 deletions lib/websocket_rails/connection_adapters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,16 @@ def user_connection?

def user
return unless user_connection?

return { id: user_identifier } if WebsocketRails.synchronize_without_auth?

controller_delegate.current_user
end

def user_identifier

return id if WebsocketRails.synchronize_without_auth?

@user_identifier ||= begin
identifier = WebsocketRails.config.user_identifier

Expand Down