/** * Get the currently authenticated user. * * @return \Illuminate\Contracts\Auth\Authenticatable|null */ public function user() { // If we've already retrieved the user for the current request we can just // return it back immediately. We do not want to fetch the user data on // every call to this method because that would be tremendously slow. if (!is_null($this->user)) { return $this->user; } $user = null; $this->parseToken(); if (!JWTAuth::check()) { return null; } $id = JWTAuth::getPayload()->get('sub'); return $this->user = $this->provider->retrieveById($id); }