laravel-swoole
laravel-swoole copied to clipboard
laravel swoole websocket auth problem with socket.io-client v3
Make sure you read Issues Guideline and answer these questions before submitting your issue. Thanks! (Any non-English issues will be closed immediately.)
- Please provide your PHP and Swoole version. (
php -vandphp --ri swoole) - Please provide your Laravel/Lumen version.
- 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 |
- 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.
-
What did you expect to see? The authenticated user object
-
What did you see instead?
Null
How can i achieve, getting the correct user?
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.
I have same problem