Closed andrii-trush closed 1 year ago
Thanks @andrii-trush for your PR but I do not think this fix is backward compatible, is it?
@imanghafoori1 interface StatefulGuard
extends from interface Guard
Here are an example in PHP sandbox https://onlinephp.io/c/99b33 with proof of backward compatible
Looks like here is an issue of this problem. https://github.com/imanghafoori1/laravel-MasterPass/issues/28
can we do it like this:
$authGuard = Auth::guard($guard);
$stateful = class_exists(StatefulGuard::class) && $authGuard instanceof StatefulGuard;
if ( $stateful || $authGuard instanceof Guard) {
// ...
}
what has happened in laravel 10 which breaks this?
@imanghafoori1 As soon as I'm making check for both interfaces, PHPStorm shows this warning
Here are my middleware where i receive an error
if (Auth::guard('sanctum')->check() && ! Auth::isLoggedInByMasterPass()) {
$request->user()->update([
'last_activity_at' => Carbon::now(),
]);
}
In this case Auth
is instance of \Illuminate\Auth\RequestGuard
and RequestGuard
implements Guard
.
As mentioned early about StatefulGuard
here are a code from laravel/framework
:
namespace Illuminate\Contracts\Auth;
interface StatefulGuard extends Guard
So my fix is safe
I just merged it for now, but since I do not have time to fully test it. I do not release a new version. Let's see if I get the time soon. So you are free to install the dev-master version.
@andrii-trush Can you use the isLoggedInByMasterPass
macro with the Request guard?
As soon as project uses Jetstream + Inertia there is an error
Method Illuminate\Auth\RequestGuard::isLoggedInByMasterPass does not exist.
in Laravel 10. Bug was detected in middleware.RequestGuard
implementsGuard
. NotStatefulGuard
.Was tested on
Laravel Framework 10.14.1
andPHP 8.1.20