Auth facade doesn't recognize macros registered on SessionGuard,RequestGuard
- Larastan Version: 9.27.0
-
--levelused: 8
Description
Call to an undefined method Illuminate\Support\Facades\Auth::authed().
Laravel code where the issue was found
$authedMacro = function (): Model {
if (($auth = Auth::user()) !== null) {
return $auth;
}
throw new UnauthorizedException();
};
SessionGuard::macro('authed', $authedMacro);
RequestGuard::macro('authed', $authedMacro);
Thank you for your report! 👋🏻
What happens if you temporarily try this?
SessionGuard::macro('authed', function (): Model {
if (($auth = Auth::user()) !== null) {
return $auth;
}
throw new UnauthorizedException();
});
Hello there,
I get the same error.
Could you share the code where this error happens?
Inside OrderController
$user = Auth::authed()
this happens with 7 of my macros auth macros.
if I switch to Auth::guard()->authed() it works as GuardDynamicStaticMethodReturnTypeExtension returns the correct guard, AuthManager's __call forwards the call to the current guard.
If I understood it correctly, this bug is caused by #1295. I proposed solutions to this in #1315. Second solution, rollback the PR and fix that issue in some other way, will fix this issue as well. After rollback the logic should be something like this:
- Pipes\Facades will get underlying class of facade Auth and send it back to pipeline
- Pipes\Auths will send Guard contract to pipeline
- Pipes\Contracts will resolve Guard contract to default guard
- Pipes\Macros will find macro function inside default guard
Right now step 4 is missing because check for macros was moved to separate extension.
Can you guys try the latest master branch and see if it fixes the issues?
Fixed with 6612298