32 lines
705 B
PHP
32 lines
705 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Client\ConnectionException;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Session;
|
|
|
|
class CheckJWTToken
|
|
{
|
|
/**
|
|
* @throws ConnectionException
|
|
*/
|
|
public function handle($request, Closure $next)
|
|
{
|
|
if (!Session::has('api_token')) {
|
|
return redirect()->route('login');
|
|
}
|
|
|
|
$response = Http::withToken(Session::get('api_token'))
|
|
->get(env('API_BASE_URL') . '/employee/me');
|
|
|
|
if ($response->failed()) {
|
|
Session::forget('api_token');
|
|
return redirect()->route('login');
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|