简体   繁体   中英

This page isn’t working localhost redirected you too many times. When I created a middleware to check login authentication

I created a middleware to check login authentication, but when I redirected the redirect, I got this error.

middleware/TwoFA.php

public function handle($request, Closure $next)
{
    $response = $next($request);
    if(Auth::check()){
        if(auth()->user()->is_verified == true){
            return $response;
        }else {
            return redirect('/verifyOTP');
        }
    }
    return $response;
}

kernel.php

'web' => [
        \App\Http\Middleware\TwoFA::class,
    ],

web.php

    Route::get('verifyOTP', 'VerifyOTPController@showVerifyPage')->name('verify');
Route::post('verifyOTP', 'VerifyOTPController@verify');
Route::group(['middleware'=>'TwoFA'], function (){
    Route::get('/home', 'HomeController@doashboard')->name('doashboard');
});

Add

use App\Http\Middleware\TwoFA; 

to web.php

and change

Route::group(['middleware' => TwoFA::class], function () {
     Route::get('/home', 'HomeController@doashboard')->name('doashboard');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM