manager = $manager; $this->generatesAuthenticationToken = $generatesAuthenticationToken; } /** * Checks if jwt token is valid. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { try { $token = explode('.', $this->manager->getToken())[1]; $decodedToken = base64_decode($token); $exchangeUser = json_decode($decodedToken, true)['user']; if ($exchangeUser['type'] === 3) { $exchangeCompanyId = $exchangeUser['company_id']; $connection = ExchangeCompanyConnection::where("exchange_company_id", $exchangeCompanyId)->first(); Log::info($request->url()); Log::info(route('api.exchange.company.connect' , $request->route('exchange_company_id'))); if(!$connection && $request->url() !== route('api.exchange.company.connect' , $request->route('exchange_company_id'))){ throw new AccessUnauthorisedException(); } } } catch (Exception $exception) { return (new ApiResponseObject('Authentication', 'To keep your account secure we need to re-validate your account', HttpStatus::ACCESS_UNAUTHORISED))->handler(); } return $next($request); } }