Pubnub chat set up for rails application

274 views Asked by At

I am hoping to clear up some confusion I have about using Pubnub with my Rails application. I am hoping to use Pubnub mainly for a chat layer among users. Users may be able to chat via iOS/Android/Web(rails) throughout the application.

** Pubnub gem is only used when creating an auth_key for user, and changing access with PAM. **

It seems to me that it is actually a serverless setup and Javascript SDK should be used instead of the Ruby SDK? The flow seems more likely to be:

  1. User registered through Devise
  2. After signed up, rails app server uses User's ID (or other uuid) to create an auth_key, stores it in the DB.

Logic when creating 1:1 chat in rails application

  1. Rails controller creates a channel, set the channel ID,
  2. creates access to the two peers.

Is this rougly the logic?

I am also not too sure whether it is okay to just put the pub_key and sub_key to the javascript client, it seems anybody can just use the pair to create all channels they want.

1

There are 1 answers

0
Tomasz Weissbek On

Yes, you're right with your insights and the logic that you laid out here is valid.

You don't need to worry about exposing your pub and sub keys to the world because of Access Manager. Secret key will be stored safely on your server and you'll be granting access to particular channels from server to specific users based on auth_key. So nobody can do anything you don't want. For more information you can also take a look at the answer here.