<?php

declare(strict_types=1);

namespace Cortex\Foundation\Http\Middleware;

use Closure;

class Authenticate
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure                 $next
     * @param string|null              $guard
     *
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        if (auth()->guard($guard)->guest()) {
            return intend([
                'url' => route('guestarea.auth.login'),
                'with' => ['warning' => trans('cortex/foundation::messages.session_required')],
            ], 401);
        }

        return $next($request);
    }
}

<?php

declare(strict_types=1);

namespace Cortex\Foundation\Http\Middleware;

use Closure;

class Authenticate
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure                 $next
     * @param string|null              $guard
     *
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        if (auth()->guard($guard)->guest()) {
            return intend([
                'url' => route('guestarea.auth.login'),
                'with' => ['warning' => trans('cortex/foundation::messages.session_required')],
            ]);
        }

        return $next($request);
    }
}

Fix wrong HTTP redirection status code
Fix wrong HTTP redirection status code
