#middleware

12 messages · Page 1 of 1 (latest)

lusty patio
#

Hi, i want to create a middleware where i check if a user is authenticated:

public function handle($request, Closure $next)
    {
        $user = $request->user();
        
        if (!$user) {
            return redirect('/');
        }
        
        if (!$user->canAccessUpStats()) {
            return redirect('/');
        }

        return $next($request);
    }

But when i do a dd of $user I get null. Can someone help me?

torn yarrow
#

make sure your middleware is after the start session middleware

lusty patio
torn yarrow
#

where are you pushing your middleware?

lusty patio
#

Its for a specific route

torn yarrow
#

okay, so where are you defining your middleware on the route?

lusty patio
#

In the web.php.

#

Or What do you mean?

torn yarrow
#

show what you have in your web.php

lusty patio
torn yarrow
#

and you've defined the upstatsAdmin middleware alias?

lusty patio
#

yes