php - Laravel problem with users which are disabled, still can log in
Get the solution ↓↓↓Problem is simple, when user has in table column ````isBlocked``` value 1, cant login. But in my case stil can. I hope so someone find problem which i dont see
App\Middleware\ActiveUser.php
<?php
namespace App\Http\Middleware;
use Illuminate\Support\Facades\Auth;
use Validator,Redirect,Response;
use Closure;
class ActiveUser
{
public function handle($request, Closure $next)
{
if (auth()->check())
{
if (auth()->user()->isBlocked == 1)
{
auth()->logout();
return response(view('expired'));
}
}
return $next($request);
}
}
App\Http\Kernel.php
protected $routeMiddleware = [
....
'active_user' => \App\Http\Middleware\ActiveUser::class,
];
web route
Route::group(['middleware' => ['active_user']], function(){
Route::get('user/{param1}&={param2}', 'AuthController@index')->name('login');
});
Answer
Solution:
I think the problem is with your condition:
if (Auth::user() && Auth::user()->isBlocked == 1) {
auth()->logout();
// you can also abort that user from accessing web pages
// App::abort(401);
return response(view('expired'));
} else {
return $next($request);
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: apache/2.4.52 (win64) openssl/1.1.1m php/8.1.2 server at localhost port 80
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.