Laravel: If isActive Middleware return false I can't login with different user until delete cookies
I have isActive middleware where I set 1 to acitive and 0 when user is not active.
isActive.php inMiddleware folder look like this:
namespace AppHttpMiddleware;
use Closure;
use IlluminateSupportFacadesAuth;
class IsActive
{
/**
* Handle an incoming request.
*
* @param IlluminateHttpRequest $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Auth::check()) {
if (Auth::user()->isActive()) {
return $next($request);
}
}
return redirect('/')->with('nonActive', 'Account is not active');
}
}
and I have method in User model:
public function isActive()
{
if ($this->is_active == 1) {
return true;
}
return false;
}
In Kernel.php in protected $routeMiddleware I add this:
'is.active' => AppHttpMiddlewareIsActive::class,
and I have group middleware in routes and all this works fine.
But, when isActive Middleware return false I can't login with different user. Always get return false as if that user is inactive too until I delete cookies. After deleting I can login just fine with user that is active.
laravel middleware
add a comment |
I have isActive middleware where I set 1 to acitive and 0 when user is not active.
isActive.php inMiddleware folder look like this:
namespace AppHttpMiddleware;
use Closure;
use IlluminateSupportFacadesAuth;
class IsActive
{
/**
* Handle an incoming request.
*
* @param IlluminateHttpRequest $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Auth::check()) {
if (Auth::user()->isActive()) {
return $next($request);
}
}
return redirect('/')->with('nonActive', 'Account is not active');
}
}
and I have method in User model:
public function isActive()
{
if ($this->is_active == 1) {
return true;
}
return false;
}
In Kernel.php in protected $routeMiddleware I add this:
'is.active' => AppHttpMiddlewareIsActive::class,
and I have group middleware in routes and all this works fine.
But, when isActive Middleware return false I can't login with different user. Always get return false as if that user is inactive too until I delete cookies. After deleting I can login just fine with user that is active.
laravel middleware
It sounds like you need to logout then login.
– adam
Nov 15 '18 at 18:53
But I can't logout if I'm not login in a first place.
– Nenad M
Nov 15 '18 at 18:54
1
Change your if toif(Auth::check && Auth::user()->isActive())
php is short circuiting.
– adam
Nov 15 '18 at 18:56
Ok, I will, but still problem exist :)
– Nenad M
Nov 15 '18 at 19:07
I think the problem might be that this middleware is blocking authentication, essentially you can'tre-login
because this middleware won't let you. Your options are to logout before attempting to login again or move the IsActive middleware underneath the authentication middleware so that you can login again without logging out.
– adam
Nov 15 '18 at 19:19
add a comment |
I have isActive middleware where I set 1 to acitive and 0 when user is not active.
isActive.php inMiddleware folder look like this:
namespace AppHttpMiddleware;
use Closure;
use IlluminateSupportFacadesAuth;
class IsActive
{
/**
* Handle an incoming request.
*
* @param IlluminateHttpRequest $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Auth::check()) {
if (Auth::user()->isActive()) {
return $next($request);
}
}
return redirect('/')->with('nonActive', 'Account is not active');
}
}
and I have method in User model:
public function isActive()
{
if ($this->is_active == 1) {
return true;
}
return false;
}
In Kernel.php in protected $routeMiddleware I add this:
'is.active' => AppHttpMiddlewareIsActive::class,
and I have group middleware in routes and all this works fine.
But, when isActive Middleware return false I can't login with different user. Always get return false as if that user is inactive too until I delete cookies. After deleting I can login just fine with user that is active.
laravel middleware
I have isActive middleware where I set 1 to acitive and 0 when user is not active.
isActive.php inMiddleware folder look like this:
namespace AppHttpMiddleware;
use Closure;
use IlluminateSupportFacadesAuth;
class IsActive
{
/**
* Handle an incoming request.
*
* @param IlluminateHttpRequest $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Auth::check()) {
if (Auth::user()->isActive()) {
return $next($request);
}
}
return redirect('/')->with('nonActive', 'Account is not active');
}
}
and I have method in User model:
public function isActive()
{
if ($this->is_active == 1) {
return true;
}
return false;
}
In Kernel.php in protected $routeMiddleware I add this:
'is.active' => AppHttpMiddlewareIsActive::class,
and I have group middleware in routes and all this works fine.
But, when isActive Middleware return false I can't login with different user. Always get return false as if that user is inactive too until I delete cookies. After deleting I can login just fine with user that is active.
laravel middleware
laravel middleware
asked Nov 15 '18 at 18:51
Nenad MNenad M
7939
7939
It sounds like you need to logout then login.
– adam
Nov 15 '18 at 18:53
But I can't logout if I'm not login in a first place.
– Nenad M
Nov 15 '18 at 18:54
1
Change your if toif(Auth::check && Auth::user()->isActive())
php is short circuiting.
– adam
Nov 15 '18 at 18:56
Ok, I will, but still problem exist :)
– Nenad M
Nov 15 '18 at 19:07
I think the problem might be that this middleware is blocking authentication, essentially you can'tre-login
because this middleware won't let you. Your options are to logout before attempting to login again or move the IsActive middleware underneath the authentication middleware so that you can login again without logging out.
– adam
Nov 15 '18 at 19:19
add a comment |
It sounds like you need to logout then login.
– adam
Nov 15 '18 at 18:53
But I can't logout if I'm not login in a first place.
– Nenad M
Nov 15 '18 at 18:54
1
Change your if toif(Auth::check && Auth::user()->isActive())
php is short circuiting.
– adam
Nov 15 '18 at 18:56
Ok, I will, but still problem exist :)
– Nenad M
Nov 15 '18 at 19:07
I think the problem might be that this middleware is blocking authentication, essentially you can'tre-login
because this middleware won't let you. Your options are to logout before attempting to login again or move the IsActive middleware underneath the authentication middleware so that you can login again without logging out.
– adam
Nov 15 '18 at 19:19
It sounds like you need to logout then login.
– adam
Nov 15 '18 at 18:53
It sounds like you need to logout then login.
– adam
Nov 15 '18 at 18:53
But I can't logout if I'm not login in a first place.
– Nenad M
Nov 15 '18 at 18:54
But I can't logout if I'm not login in a first place.
– Nenad M
Nov 15 '18 at 18:54
1
1
Change your if to
if(Auth::check && Auth::user()->isActive())
php is short circuiting.– adam
Nov 15 '18 at 18:56
Change your if to
if(Auth::check && Auth::user()->isActive())
php is short circuiting.– adam
Nov 15 '18 at 18:56
Ok, I will, but still problem exist :)
– Nenad M
Nov 15 '18 at 19:07
Ok, I will, but still problem exist :)
– Nenad M
Nov 15 '18 at 19:07
I think the problem might be that this middleware is blocking authentication, essentially you can't
re-login
because this middleware won't let you. Your options are to logout before attempting to login again or move the IsActive middleware underneath the authentication middleware so that you can login again without logging out.– adam
Nov 15 '18 at 19:19
I think the problem might be that this middleware is blocking authentication, essentially you can't
re-login
because this middleware won't let you. Your options are to logout before attempting to login again or move the IsActive middleware underneath the authentication middleware so that you can login again without logging out.– adam
Nov 15 '18 at 19:19
add a comment |
2 Answers
2
active
oldest
votes
Your route group:
Route::group(['middleware' => 'auth'], function () {
// your active and auth user routes
});
If you want a user to be active in order to authenticate, use a global scope in your User model:
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentBuilder;
class User extends Model
{
...
protected static function boot()
{
parent::boot();
static::addGlobalScope('isactive', function (Builder $builder) {
$builder->where('is_active', '=', 1);
});
}
...
}
This way a user will not be found unless they are active and you won't need the IsActive middleware.
Source: https://laravel.com/docs/5.7/eloquent#global-scopes
To customize authentication failure errors override sendFailedLoginResponse
in your LoginController
protected function sendFailedLoginResponse(Request $request)
{
return redirect('/')->with('nonActive', 'Account is not active');
}
But, I don't have nonActive user routes so I don't understand what to put there, if user is not active (is_active column is 0) the simply not suppose to login. All else routes shold be in ['middleware'=>'is.active'] group. Also have admin and super.admin group but that not related to question.
– Nenad M
Nov 15 '18 at 19:33
@NenadM updated answer, see if that helps
– adam
Nov 15 '18 at 19:47
No, if I add that to User mode, error appear: Type error: Argument 1 passed to AppUser::App{closure}() must be an instance of AppBuilder, instance of IlluminateDatabaseEloquentBuilder given, called in C:xampphtdocskapCMSvendorlaravelframeworksrcIlluminateDatabaseEloquentBuilder.php on line 921
– Nenad M
Nov 15 '18 at 21:27
@NenadM you will needuse IlluminateDatabaseEloquentBuilder;
I've updated the answer.
– adam
Nov 15 '18 at 21:28
That work and now is working fine but new problem is that isActive middleware seems no more working because message 'Account is not active" not appear. Now instead of "Account is not active" message I get as that user username or password is not true.
– Nenad M
Nov 15 '18 at 21:35
|
show 7 more comments
Don't redirect if Auth::check() returns false..
Change your logic around:
if (Auth::check()) {
if (!Auth::user()->isActive()) {
return redirect('/')->with('nonActive', 'Account is not active');
}
}
return $next($request);
You could also simplify that to one if statement. You may also consider logging the user out before you redirect.
It doesn't work, still shows for all accounts that is not active either some is active.
– Nenad M
Nov 15 '18 at 19:07
If it's redirecting with this code when the user is active, then your problem lies with your isActive() method. Debug and make sure everything is set properly.
– Devon
Nov 15 '18 at 19:19
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326126%2flaravel-if-isactive-middleware-return-false-i-cant-login-with-different-user-u%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your route group:
Route::group(['middleware' => 'auth'], function () {
// your active and auth user routes
});
If you want a user to be active in order to authenticate, use a global scope in your User model:
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentBuilder;
class User extends Model
{
...
protected static function boot()
{
parent::boot();
static::addGlobalScope('isactive', function (Builder $builder) {
$builder->where('is_active', '=', 1);
});
}
...
}
This way a user will not be found unless they are active and you won't need the IsActive middleware.
Source: https://laravel.com/docs/5.7/eloquent#global-scopes
To customize authentication failure errors override sendFailedLoginResponse
in your LoginController
protected function sendFailedLoginResponse(Request $request)
{
return redirect('/')->with('nonActive', 'Account is not active');
}
But, I don't have nonActive user routes so I don't understand what to put there, if user is not active (is_active column is 0) the simply not suppose to login. All else routes shold be in ['middleware'=>'is.active'] group. Also have admin and super.admin group but that not related to question.
– Nenad M
Nov 15 '18 at 19:33
@NenadM updated answer, see if that helps
– adam
Nov 15 '18 at 19:47
No, if I add that to User mode, error appear: Type error: Argument 1 passed to AppUser::App{closure}() must be an instance of AppBuilder, instance of IlluminateDatabaseEloquentBuilder given, called in C:xampphtdocskapCMSvendorlaravelframeworksrcIlluminateDatabaseEloquentBuilder.php on line 921
– Nenad M
Nov 15 '18 at 21:27
@NenadM you will needuse IlluminateDatabaseEloquentBuilder;
I've updated the answer.
– adam
Nov 15 '18 at 21:28
That work and now is working fine but new problem is that isActive middleware seems no more working because message 'Account is not active" not appear. Now instead of "Account is not active" message I get as that user username or password is not true.
– Nenad M
Nov 15 '18 at 21:35
|
show 7 more comments
Your route group:
Route::group(['middleware' => 'auth'], function () {
// your active and auth user routes
});
If you want a user to be active in order to authenticate, use a global scope in your User model:
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentBuilder;
class User extends Model
{
...
protected static function boot()
{
parent::boot();
static::addGlobalScope('isactive', function (Builder $builder) {
$builder->where('is_active', '=', 1);
});
}
...
}
This way a user will not be found unless they are active and you won't need the IsActive middleware.
Source: https://laravel.com/docs/5.7/eloquent#global-scopes
To customize authentication failure errors override sendFailedLoginResponse
in your LoginController
protected function sendFailedLoginResponse(Request $request)
{
return redirect('/')->with('nonActive', 'Account is not active');
}
But, I don't have nonActive user routes so I don't understand what to put there, if user is not active (is_active column is 0) the simply not suppose to login. All else routes shold be in ['middleware'=>'is.active'] group. Also have admin and super.admin group but that not related to question.
– Nenad M
Nov 15 '18 at 19:33
@NenadM updated answer, see if that helps
– adam
Nov 15 '18 at 19:47
No, if I add that to User mode, error appear: Type error: Argument 1 passed to AppUser::App{closure}() must be an instance of AppBuilder, instance of IlluminateDatabaseEloquentBuilder given, called in C:xampphtdocskapCMSvendorlaravelframeworksrcIlluminateDatabaseEloquentBuilder.php on line 921
– Nenad M
Nov 15 '18 at 21:27
@NenadM you will needuse IlluminateDatabaseEloquentBuilder;
I've updated the answer.
– adam
Nov 15 '18 at 21:28
That work and now is working fine but new problem is that isActive middleware seems no more working because message 'Account is not active" not appear. Now instead of "Account is not active" message I get as that user username or password is not true.
– Nenad M
Nov 15 '18 at 21:35
|
show 7 more comments
Your route group:
Route::group(['middleware' => 'auth'], function () {
// your active and auth user routes
});
If you want a user to be active in order to authenticate, use a global scope in your User model:
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentBuilder;
class User extends Model
{
...
protected static function boot()
{
parent::boot();
static::addGlobalScope('isactive', function (Builder $builder) {
$builder->where('is_active', '=', 1);
});
}
...
}
This way a user will not be found unless they are active and you won't need the IsActive middleware.
Source: https://laravel.com/docs/5.7/eloquent#global-scopes
To customize authentication failure errors override sendFailedLoginResponse
in your LoginController
protected function sendFailedLoginResponse(Request $request)
{
return redirect('/')->with('nonActive', 'Account is not active');
}
Your route group:
Route::group(['middleware' => 'auth'], function () {
// your active and auth user routes
});
If you want a user to be active in order to authenticate, use a global scope in your User model:
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentBuilder;
class User extends Model
{
...
protected static function boot()
{
parent::boot();
static::addGlobalScope('isactive', function (Builder $builder) {
$builder->where('is_active', '=', 1);
});
}
...
}
This way a user will not be found unless they are active and you won't need the IsActive middleware.
Source: https://laravel.com/docs/5.7/eloquent#global-scopes
To customize authentication failure errors override sendFailedLoginResponse
in your LoginController
protected function sendFailedLoginResponse(Request $request)
{
return redirect('/')->with('nonActive', 'Account is not active');
}
edited Nov 15 '18 at 21:44
answered Nov 15 '18 at 19:24
adamadam
927811
927811
But, I don't have nonActive user routes so I don't understand what to put there, if user is not active (is_active column is 0) the simply not suppose to login. All else routes shold be in ['middleware'=>'is.active'] group. Also have admin and super.admin group but that not related to question.
– Nenad M
Nov 15 '18 at 19:33
@NenadM updated answer, see if that helps
– adam
Nov 15 '18 at 19:47
No, if I add that to User mode, error appear: Type error: Argument 1 passed to AppUser::App{closure}() must be an instance of AppBuilder, instance of IlluminateDatabaseEloquentBuilder given, called in C:xampphtdocskapCMSvendorlaravelframeworksrcIlluminateDatabaseEloquentBuilder.php on line 921
– Nenad M
Nov 15 '18 at 21:27
@NenadM you will needuse IlluminateDatabaseEloquentBuilder;
I've updated the answer.
– adam
Nov 15 '18 at 21:28
That work and now is working fine but new problem is that isActive middleware seems no more working because message 'Account is not active" not appear. Now instead of "Account is not active" message I get as that user username or password is not true.
– Nenad M
Nov 15 '18 at 21:35
|
show 7 more comments
But, I don't have nonActive user routes so I don't understand what to put there, if user is not active (is_active column is 0) the simply not suppose to login. All else routes shold be in ['middleware'=>'is.active'] group. Also have admin and super.admin group but that not related to question.
– Nenad M
Nov 15 '18 at 19:33
@NenadM updated answer, see if that helps
– adam
Nov 15 '18 at 19:47
No, if I add that to User mode, error appear: Type error: Argument 1 passed to AppUser::App{closure}() must be an instance of AppBuilder, instance of IlluminateDatabaseEloquentBuilder given, called in C:xampphtdocskapCMSvendorlaravelframeworksrcIlluminateDatabaseEloquentBuilder.php on line 921
– Nenad M
Nov 15 '18 at 21:27
@NenadM you will needuse IlluminateDatabaseEloquentBuilder;
I've updated the answer.
– adam
Nov 15 '18 at 21:28
That work and now is working fine but new problem is that isActive middleware seems no more working because message 'Account is not active" not appear. Now instead of "Account is not active" message I get as that user username or password is not true.
– Nenad M
Nov 15 '18 at 21:35
But, I don't have nonActive user routes so I don't understand what to put there, if user is not active (is_active column is 0) the simply not suppose to login. All else routes shold be in ['middleware'=>'is.active'] group. Also have admin and super.admin group but that not related to question.
– Nenad M
Nov 15 '18 at 19:33
But, I don't have nonActive user routes so I don't understand what to put there, if user is not active (is_active column is 0) the simply not suppose to login. All else routes shold be in ['middleware'=>'is.active'] group. Also have admin and super.admin group but that not related to question.
– Nenad M
Nov 15 '18 at 19:33
@NenadM updated answer, see if that helps
– adam
Nov 15 '18 at 19:47
@NenadM updated answer, see if that helps
– adam
Nov 15 '18 at 19:47
No, if I add that to User mode, error appear: Type error: Argument 1 passed to AppUser::App{closure}() must be an instance of AppBuilder, instance of IlluminateDatabaseEloquentBuilder given, called in C:xampphtdocskapCMSvendorlaravelframeworksrcIlluminateDatabaseEloquentBuilder.php on line 921
– Nenad M
Nov 15 '18 at 21:27
No, if I add that to User mode, error appear: Type error: Argument 1 passed to AppUser::App{closure}() must be an instance of AppBuilder, instance of IlluminateDatabaseEloquentBuilder given, called in C:xampphtdocskapCMSvendorlaravelframeworksrcIlluminateDatabaseEloquentBuilder.php on line 921
– Nenad M
Nov 15 '18 at 21:27
@NenadM you will need
use IlluminateDatabaseEloquentBuilder;
I've updated the answer.– adam
Nov 15 '18 at 21:28
@NenadM you will need
use IlluminateDatabaseEloquentBuilder;
I've updated the answer.– adam
Nov 15 '18 at 21:28
That work and now is working fine but new problem is that isActive middleware seems no more working because message 'Account is not active" not appear. Now instead of "Account is not active" message I get as that user username or password is not true.
– Nenad M
Nov 15 '18 at 21:35
That work and now is working fine but new problem is that isActive middleware seems no more working because message 'Account is not active" not appear. Now instead of "Account is not active" message I get as that user username or password is not true.
– Nenad M
Nov 15 '18 at 21:35
|
show 7 more comments
Don't redirect if Auth::check() returns false..
Change your logic around:
if (Auth::check()) {
if (!Auth::user()->isActive()) {
return redirect('/')->with('nonActive', 'Account is not active');
}
}
return $next($request);
You could also simplify that to one if statement. You may also consider logging the user out before you redirect.
It doesn't work, still shows for all accounts that is not active either some is active.
– Nenad M
Nov 15 '18 at 19:07
If it's redirecting with this code when the user is active, then your problem lies with your isActive() method. Debug and make sure everything is set properly.
– Devon
Nov 15 '18 at 19:19
add a comment |
Don't redirect if Auth::check() returns false..
Change your logic around:
if (Auth::check()) {
if (!Auth::user()->isActive()) {
return redirect('/')->with('nonActive', 'Account is not active');
}
}
return $next($request);
You could also simplify that to one if statement. You may also consider logging the user out before you redirect.
It doesn't work, still shows for all accounts that is not active either some is active.
– Nenad M
Nov 15 '18 at 19:07
If it's redirecting with this code when the user is active, then your problem lies with your isActive() method. Debug and make sure everything is set properly.
– Devon
Nov 15 '18 at 19:19
add a comment |
Don't redirect if Auth::check() returns false..
Change your logic around:
if (Auth::check()) {
if (!Auth::user()->isActive()) {
return redirect('/')->with('nonActive', 'Account is not active');
}
}
return $next($request);
You could also simplify that to one if statement. You may also consider logging the user out before you redirect.
Don't redirect if Auth::check() returns false..
Change your logic around:
if (Auth::check()) {
if (!Auth::user()->isActive()) {
return redirect('/')->with('nonActive', 'Account is not active');
}
}
return $next($request);
You could also simplify that to one if statement. You may also consider logging the user out before you redirect.
answered Nov 15 '18 at 19:00
DevonDevon
23.4k42747
23.4k42747
It doesn't work, still shows for all accounts that is not active either some is active.
– Nenad M
Nov 15 '18 at 19:07
If it's redirecting with this code when the user is active, then your problem lies with your isActive() method. Debug and make sure everything is set properly.
– Devon
Nov 15 '18 at 19:19
add a comment |
It doesn't work, still shows for all accounts that is not active either some is active.
– Nenad M
Nov 15 '18 at 19:07
If it's redirecting with this code when the user is active, then your problem lies with your isActive() method. Debug and make sure everything is set properly.
– Devon
Nov 15 '18 at 19:19
It doesn't work, still shows for all accounts that is not active either some is active.
– Nenad M
Nov 15 '18 at 19:07
It doesn't work, still shows for all accounts that is not active either some is active.
– Nenad M
Nov 15 '18 at 19:07
If it's redirecting with this code when the user is active, then your problem lies with your isActive() method. Debug and make sure everything is set properly.
– Devon
Nov 15 '18 at 19:19
If it's redirecting with this code when the user is active, then your problem lies with your isActive() method. Debug and make sure everything is set properly.
– Devon
Nov 15 '18 at 19:19
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326126%2flaravel-if-isactive-middleware-return-false-i-cant-login-with-different-user-u%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It sounds like you need to logout then login.
– adam
Nov 15 '18 at 18:53
But I can't logout if I'm not login in a first place.
– Nenad M
Nov 15 '18 at 18:54
1
Change your if to
if(Auth::check && Auth::user()->isActive())
php is short circuiting.– adam
Nov 15 '18 at 18:56
Ok, I will, but still problem exist :)
– Nenad M
Nov 15 '18 at 19:07
I think the problem might be that this middleware is blocking authentication, essentially you can't
re-login
because this middleware won't let you. Your options are to logout before attempting to login again or move the IsActive middleware underneath the authentication middleware so that you can login again without logging out.– adam
Nov 15 '18 at 19:19