my routes protected by auth middleware don't redirect to login page

I get this error every time I visit a route protected by auth middleware when am not authenticated and started session Illuminate\Session\Middleware\StartSession::addCookieToResponse(): Argument #1 ($response) must be of type Symfony\Component\HttpFoundation\Response, null given, called in /home/u684103588/domains/chccug.com/public_html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php on line 125 I have alternated the middlewares in the app to no avail
Solution:
Deleted all the default files and installed fresh installation of Laravel 10, added all the custom codes run composer install and every started working perfectly fine
Jump to solution
11 Replies
Virgil
Virgil13mo ago
Hello Obala, Can you show us your web.php file? I think the problem is with the routing.
Obala
Obala13mo ago
here is my route and the middleware used
Route::middleware(['auth', 'verified', 'xss', 'checkUserStatus'])->group(function () {
Route::get('profile', [UserController::class, 'editProfile']);
Route::post('change-password', [UserController::class, 'changePassword']);
Route::post('profile-update', [UserController::class, 'profileUpdate']);
Route::post('update-language', [UserController::class, 'updateLanguage']);
});
Route::middleware(['auth', 'verified', 'xss', 'checkUserStatus'])->group(function () {
Route::get('profile', [UserController::class, 'editProfile']);
Route::post('change-password', [UserController::class, 'changePassword']);
Route::post('profile-update', [UserController::class, 'profileUpdate']);
Route::post('update-language', [UserController::class, 'updateLanguage']);
});
Virgil
Virgil13mo ago
Do you have defined, which route (in the UserController) Laravel has to follow when you're not logged in?
Obala
Obala13mo ago
yes, they are all setup and working, i only get the error say when i visit /profile without logging in first, butt when i visit route like /login or /register or the front routes which does not require authentication i don't get any error
tuto1902
tuto190213mo ago
Can you show me the middleware array in app\Http\Kernel.php? Also, can I see the use statement for the Response class inside the UserController class I see that you have a checkUserStatus in the middleware as well. Can I take a look at that middleware class too?
Obala
Obala13mo ago
Let me do so in a minute
Obala
Obala13mo ago
thats the app\http\kernel.php
Obala
Obala13mo ago
class CheckUserStatus
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);

if (Auth::check() && ! $request->user()->status) {
Auth::logout();
Flash::error('Your Account is currently disabled, please contact to administrator.');

return redirect()->back();
}

return $response;
}
}
class CheckUserStatus
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);

if (Auth::check() && ! $request->user()->status) {
Auth::logout();
Flash::error('Your Account is currently disabled, please contact to administrator.');

return redirect()->back();
}

return $response;
}
}
CheckuserStatus middleware
Obala
Obala13mo ago
usercontroller\
Obala
Obala13mo ago
there's this issue with the api routes
Unable to prepare route [password/email] for serialization. Another route has already been assigned name [password.email].

at D:\ivan\chcc-update\vendor\laravel\framework\src\Illuminate\Routing\AbstractRouteCollection.php:247
243▕ $route->name($this->generateRouteName());
244▕
245▕ $this->add($route);
246▕ } elseif (! is_null($symfonyRoutes->get($name))) {
➜ 247▕ throw new LogicException("Unable to prepare route [{$route->uri}] for serialization. Another route has already been assigned name [{$name}].");
248▕ }
249▕
250▕ $symfonyRoutes->add($route->getName(), $route->toSymfonyRoute());
251▕

1 D:\ivan\chcc-update\vendor\laravel\framework\src\Illuminate\Routing\AbstractRouteCollection.php:208
Illuminate\Routing\AbstractRouteCollection::addToSymfonyRoutesCollection(Object(Symfony\Component\Routing\RouteCollection), Object(Illuminate\Routing\Route))

2 D:\ivan\chcc-update\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php:246
Illuminate\Routing\AbstractRouteCollection::toSymfonyRouteCollection()
Unable to prepare route [password/email] for serialization. Another route has already been assigned name [password.email].

at D:\ivan\chcc-update\vendor\laravel\framework\src\Illuminate\Routing\AbstractRouteCollection.php:247
243▕ $route->name($this->generateRouteName());
244▕
245▕ $this->add($route);
246▕ } elseif (! is_null($symfonyRoutes->get($name))) {
➜ 247▕ throw new LogicException("Unable to prepare route [{$route->uri}] for serialization. Another route has already been assigned name [{$name}].");
248▕ }
249▕
250▕ $symfonyRoutes->add($route->getName(), $route->toSymfonyRoute());
251▕

1 D:\ivan\chcc-update\vendor\laravel\framework\src\Illuminate\Routing\AbstractRouteCollection.php:208
Illuminate\Routing\AbstractRouteCollection::addToSymfonyRoutesCollection(Object(Symfony\Component\Routing\RouteCollection), Object(Illuminate\Routing\Route))

2 D:\ivan\chcc-update\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php:246
Illuminate\Routing\AbstractRouteCollection::toSymfonyRouteCollection()
i don't if its the cause of this mess this happens when i run php artisan route:cache
Solution
Obala
Obala13mo ago
Deleted all the default files and installed fresh installation of Laravel 10, added all the custom codes run composer install and every started working perfectly fine
Want results from more Discord servers?
Add your server