When I am trying to return Auth::user() or return $request->user(), the handle($request, Closure $next, ...$guards) function (in Authenticate.php middleware) returns null. This middleware execute for every route. I am trying to return Auth::user() because i need an email of currently logged user and returning Auth::user() is for checking if I can get informations about currently logged user.
<?php
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Closure;
use Illuminate\Support\Facades\Cookie;
use PHPOpenSourceSaver\JWTAuth\Exceptions\TokenExpiredException;
use PHPOpenSourceSaver\JWTAuth\Exceptions\TokenInvalidException;
use PHPOpenSourceSaver\JWTAuth\Facades\JWTAuth;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string|null
*/
protected function redirectTo($request)
{
if (!$request->expectsJson()) {
return route('login');
}
}
public function handle($request, Closure $next, ...$guards)
{
return Auth::user();
return $next($request);
}
}
Auth::user()? Return it to where?