mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 12:33:56 +00:00
35 lines
826 B
PHP
35 lines
826 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Classes\Exceptions\AccessUnauthorisedException;
|
|
use App\Classes\ValueObjects\Constants\HttpStatus;
|
|
use App\Classes\ValueObjects\Response\ApiResponseObject;
|
|
use Closure;
|
|
use Exception;
|
|
|
|
class ValidateToken
|
|
{
|
|
/**
|
|
* Checks if jwt token is valid.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \Closure $next
|
|
* @return mixed
|
|
*/
|
|
public function handle($request, Closure $next)
|
|
{
|
|
try {
|
|
|
|
if(!auth('api')->check()){ throw new AccessUnauthorisedException(); }
|
|
|
|
} catch (Exception) {
|
|
|
|
return (new ApiResponseObject('Authentication', 'To keep your account secure we need to re-validate your account', HttpStatus::ACCESS_UNAUTHORISED))->handler();
|
|
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|