tymondesigns / jwt-auth

🔐 JSON Web Token Authentication for Laravel & Lumen
https://jwt-auth.com
MIT License
11.28k stars 1.55k forks source link

jwt.auth and auth middleware common use #1085

Open mediaceh opened 7 years ago

mediaceh commented 7 years ago

Is it possible use it common in controller constructor as

public function __construct()
{
    $this->middleware(['auth','jwt.auth']);
}

or not?

superbiche commented 7 years ago

Yes. I use it this way (but without the auth middleware that is useless to me).

public function __construct()  
{  
    $this->middleware('jwt.auth');  
    parent::__construct();  
}  

You can even use it partially like explained in Laravel docs (5.2)

$this->middleware('jwt.auth', ['except' => [
            'index',
            'show'
]]);  

5.3 way (I'm still using the 5.2 way which is OK)

$this->middleware('jwt.auth')->except([
            'index',
            'show'
]);