Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

laravel swoole websocket auth problem with socket.io-client v3 #498

Open
SchahinRohani opened this issue Jul 27, 2021 · 2 comments
Open

Comments

@SchahinRohani
Copy link

Make sure you read Issues Guideline and answer these questions before submitting your issue. Thanks!
(Any non-English issues will be closed immediately.)

  1. Please provide your PHP and Swoole version. (php -v and php --ri swoole)
  2. Please provide your Laravel/Lumen version.
  3. Which release version of this package are you using?
Software Version
PHP 8.0.8
Swoole 4.7.0
Laravel 8.51.0
laravel-swoole 2.8
  1. What did you do? If possible, provide a recipe for reproducing the error.

config/swoole_http.php

'providers' => [
    Illuminate\Pagination\PaginationServiceProvider::class,
    Illuminate\Auth\AuthServiceProvider::class,
    \App\Providers\AuthServiceProvider::class,
],

config/swoole_websocket.php

'middleware' => [
     SwooleTW\Http\Websocket\Middleware\DecryptCookies::class,
    SwooleTW\Http\Websocket\Middleware\StartSession::class,
    SwooleTW\Http\Websocket\Middleware\Authenticate::class,
],

Socket.io-Client v3

this.socket = io('http://localhost:80',
  {
    transports: ['websocket'],
    withCredentials: true,
  }
);

routes/websocket.php

Websocket::on('connect', function ($websocket, $request) {
  var_dump("Trying to Access Authenticated User!");
  $user = $request->user();
  var_dump( $user );
  var_dump( auth()->user() );
  }

I am also using Laravel Sanctum.

  1. What did you expect to see?
    The authenticated user object

  2. What did you see instead?

Null

How can i achieve, getting the correct user?

@michabbb
Copy link

interesting, after reading the wiki and finding out that there is a middleware for sockets to authenticate a user, I have no clue how to authenticate a user while establishing a socket connection. I would be happy if the author could show us an example that demonstrates what the client has to do.

@evecimar
Copy link

I have same problem

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants