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

websocket can not get auth user in laravel5.8 #320

Closed
fengxin2017 opened this issue Aug 10, 2019 · 2 comments
Closed

websocket can not get auth user in laravel5.8 #320

fengxin2017 opened this issue Aug 10, 2019 · 2 comments
Labels

Comments

@fengxin2017
Copy link

fengxin2017 commented Aug 10, 2019

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)
    7.2.21-1+ubuntu18.04.1+deb.sury.org+1 and swoole-4.4.3

  2. Please provide your Laravel/Lumen version.
    laravel5.8.31

  3. Which release version of this package are you using?
    2.6

  4. What did you do? If possible, provide a recipe for reproducing the error.

Websocket::on('connect', function ($websocket, Request $request) {
    $user = auth()->user();  
    dump($user);
});
  1. What did you expect to see?
Websocket::on('connect', function ($websocket, Request $request) {
    $user = auth()->user();  // get the  authorized user 
});
  1. What did you see instead?
Websocket::on('connect', function ($websocket, Request $request) {
    $user = auth()->user(); 
   //here, always return null 
    dump($user); 
});

there is not option named session on laravel5.8. so add a option named session whatever just not null will fix it. did i missed somthing in doc?

SwooleTW\Http\Websocket\Middleware\StartSession

public function handle($request, Closure $next)
 {
    if ($this->sessionConfigured()) {
        $request->setLaravelSession($this->startSession($request));
    }

    return $next($request);
 }

// problem here
protected function sessionConfigured()
{
    return Arr::get($this->manager->getSessionConfig(), 'session') !== null;
}

@albertcht
Copy link
Member

albertcht commented Aug 14, 2019

Hi @fengxin2017 ,

The middleware provided in this package is just for demonstration, but may not be compatible for all versions of Laravel.

You can implement your own middleware based on your real use case.

@fengxin2017
Copy link
Author

@albertcht got it thanks a lot.

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

No branches or pull requests

2 participants