How i can define two broadcasting auth routes for web middleware and api middleware?
I can define Broadcast::routes(); for web or Broadcast::routes( [ 'middleware' => [ 'api', 'jwt.auth' ] ] ); for api. But it doesn't work common.
For what it add default web middleware to broadcasting auth route?
`public function routes(array $attributes = null)
{
if ($this->app->routesAreCached()) {
return;
}
$attributes = $attributes ?: ['middleware' => ['web']];
$this->app['router']->group($attributes, function ($router) {
$router->post('/broadcasting/auth', BroadcastController::class.'@authenticate');
});
}`
oK, i deleted default web middleware and added parse user from token to broadcast auth callback.
`Broadcast::channel('App.User.*', function ($request, $userId) {
$result = (int) $request->user()->id === (int) $userId;
if($result) {
return $result;
}
else {
$user = \Tymon\JWTAuth::parseToken()->authenticate();
if($user) {
$request->setUserResolver(function () use ($user) {
return $user;
});
return (int) $user->id === (int) $userId;;
}
}
return false;
});`
`public function routes(array $attributes = null)
{
if ($this->app->routesAreCached()) {
return;
}
$attributes = [];
$this->app['router']->group($attributes, function ($router) {
$router->post('/broadcasting/auth', BroadcastController::class.'@authenticate');
});
}`
It works at first sight.
Where could I make a mistake?
This is not StackOverflow, this will get closed ASAP.
Note: you can edit your posts on GH so no need to post multiple times.
Oh really? The fact that I can not use Broadcasting for Api and the Web at the same time is not a bug? So it's planned?
This information is for other users. If you do not like it, do not read it.
You should ask this on the forums.