Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Authenticate | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| handle | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Middleware; |
| 4 | |
| 5 | use App\Repositories\Doctrine\UsuariosRepository; |
| 6 | |
| 7 | use Firebase\JWT\JWT; |
| 8 | use Firebase\JWT\Key; |
| 9 | use Closure; |
| 10 | use Illuminate\Contracts\Auth\Factory as Auth; |
| 11 | |
| 12 | class Authenticate |
| 13 | { |
| 14 | public function __construct(protected Auth $auth){} |
| 15 | |
| 16 | public function handle($request, Closure $next, $guard = null) |
| 17 | { |
| 18 | try { |
| 19 | if(is_null(\Auth::user())) { |
| 20 | throw new \Exception(); |
| 21 | } |
| 22 | |
| 23 | return $next($request); |
| 24 | } catch (\Exception $e) { |
| 25 | return response()->json('Não autorizado', 401); |
| 26 | } |
| 27 | } |
| 28 | } |