Answer the question
In order to leave comments, you need to log in
Laravel: why redirect to login even after authorization?
When trying to log in or register, it redirects to the login, as seen in the picture below.
Here are the files involved in the authentication process:
1) Routes: web.php
Auth::routes();
Route::get('doc/', function () {
return view('welcome');
});
Route::get('/confirm', function()
{
return view('confirm');
})->name('confirm');
Route::post('/confirm', '[email protected]')->name('addworker');
Route::get('users/{id}', '[email protected]')->where('id', '[0-9]+')->name('account');
Route::get('/home', '[email protected]')->name('home');
protected function redirectTo()
{
return route('account',['id'=> auth()->user()->id]);
}
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
use App\Employee;
class CheckConfirm
{
public function handle($request, Closure $next)
{
if(Auth::check()) //если пользователь авторизован
{
$id = Auth::id(); //сохраняем его id
$empl = Employee::where('user_id','=', $id)->first();
dump($empl);
if($empl == null)// если запрос вернул null
{
return redirect()->route('confirm'); //заставляем его конформится
}
else
{
dump($empl);
return $next($request); //то пропускаем пользователя дальше
}
}
else
{
return redirect()->route('login');
}
}
}
public function __construct()
{
$this->middleware('auth');
$this->middleware('confirmated');
}
public function show($id)
{
return view('account');
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question