Skip to content

Instantly share code, notes, and snippets.

@tokafish
Last active December 9, 2016 20:44
Show Gist options
  • Save tokafish/8dbefd858b1649d0804e to your computer and use it in GitHub Desktop.
Save tokafish/8dbefd858b1649d0804e to your computer and use it in GitHub Desktop.
Pusher Authentication
class PusherController < ApplicationController
protect_from_forgery except: :auth
def auth
response = Pusher[params[:channel_name]].authenticate params[:socket_id],
user_id: params[:id],
user_info: { name: params[:name] }
render json: response
end
end
Pusher.app_id = 'YOUR_APP_ID'
Pusher.key = 'YOUR_APP_KEY'
Pusher.secret = 'YOUR_APP_SECRET'
match '/pusher/auth' => 'pusher#auth', via: :post
var currentUser = {
name: 'Tommy',
id: 42
};
var pusher = new Pusher('YOUR_PUSHER_KEY', {
authEndpoint: '/pusher/auth',
auth: {
params: currentUser
}
});
var channel = pusher.subscribe('presence-chat');
channel.bind('pusher:subscription_succeeded', function() {
console.log('Channel members:', channel.members);
});
Copy link

ghost commented Aug 23, 2016

While implementing this I am getting this error "undefined method `length' for nil:NilClass" what could be this and why it is comming?

@lutsiukAV
Copy link

I have the same problem as @Ami2810, please help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment