Framework: Two broadcasting auth routes for different middleware

Created on 10 Jun 2017  路  5Comments  路  Source: laravel/framework

  • Laravel Version: 5.3.#
  • PHP Version:
  • Database Driver & Version:

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.

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

YannPl picture YannPl  路  3Comments

JamborJan picture JamborJan  路  3Comments

CupOfTea696 picture CupOfTea696  路  3Comments

kerbylav picture kerbylav  路  3Comments

lzp819739483 picture lzp819739483  路  3Comments