Harish Battula
Harish Battula

Reputation: 67

This page isn’t working127.0.0.1 redirected you too many times

web.php

Route::view('/','home');
Route::view('login','login');

Globalmiddleware.php

public function handle($request, Closure $next)
{
    if(true) return redirect('login');
    else return $next($request);
}

i'm redirecting default page to login page but i got some strange result which shows login page isn't working

This page isn’t working
127.0.0.1 redirected you too many times.
Try clearing your cookies.
ERR_TOO_MANY_REDIRECTS

remember i have login and home views

Upvotes: 0

Views: 4333

Answers (2)

Ajay Sharma
Ajay Sharma

Reputation: 1

Please check your route file to ensure that you have correctly created a new route. Verify their location and validation code.

Route::middleware('auth')->group(function () {
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});

Upvotes: 0

John Lobo
John Lobo

Reputation: 15319

In Globalmiddleware you have written if condition with true.So it redirecting to login page and next it will execute again so its going to infinite redirection

 if(true) return redirect('login');

so better check user logged in or not

public function handle($request, Closure $next)
{
    if(!auth()->check){
      return redirect('login');
    }

    return $next($request);

}

also make sure declare middleware in protected $routeMiddleware in kernal.php and dont assign this middleware to login route

Upvotes: 1

Related Questions