mercredi 1 janvier 2020

Laravel - Custom Auth Middleware not redirecting properly for unauthorized user

I have created a custom auth controller for recognising unauthorized user and redirect them to login path. If logged in the middlewre is working absolutely fine, but showing error if not logged in. Here is my code

Middleware:

    class CheckUserAuthenticated
{
    public function handle($request, Closure $next)
    {
        if(auth()->check()) {
            $user_id =  auth()->user()->id;
            define('authenticated_user_id' ,$user_id);
            return $next($request);
        }
        return redirect('login'); // this code is not working
    }
}

Error:

enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire