ratchet_client icon indicating copy to clipboard operation
ratchet_client copied to clipboard

Authentication Error

Open adrianrz opened this issue 5 years ago • 3 comments

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

adrianrz avatar Mar 04 '19 14:03 adrianrz

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;
 }

primapwd avatar Mar 06 '19 04:03 primapwd

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

adrianrz avatar Mar 07 '19 04:03 adrianrz

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

romainrg avatar Mar 07 '19 08:03 romainrg