romainrg / ratchet_client

CodeIgniter library who allow you to make powerfull applications with realtime interactions by using Websocket technology and Ratchetphp 🚀🚀
GNU General Public License v3.0
38 stars 24 forks source link

Authentication Error #2

Open adrianrz opened 5 years ago

adrianrz commented 5 years ago

Hi Roman, thanks for sharing your great work I just installed your library and when I run; php index.php welcome index It shows me an error: [31mAuthentication callback is required, you must set it before run server, aborting .. [0m I have experience in CI and followed the steps in detail. Any idea why it gives error? Regards

primapwd commented 5 years ago

It seems that you set 'auth' => true in config/ratchet_client.php. If so, you must provide an authentication callback before running websocket.

Add this on your controller index function

$this->ratchet_client->set_callback('auth', array($this, '_auth'));
$this->ratchet_client->run();

And this function for authentication

public function _auth($datas = null)
 {
     // Here you can verify everything you want to perform user login.
     // However, method must return integer (client ID) if auth succedeed and false if not.
     return (!empty($datas->user_id)) ? $datas->user_id : false;
 }
adrianrz commented 5 years ago

Ok, this auth can be for ex. ion_auth library?

romainrg commented 5 years ago

Hello

You can define an auth function and do everything you wan't inside, otherwise you have to set the auth config => false, but not recommended

Thanks