fix: guard Auth::guard('sanctum') call with try-catch in TeacherPortalAuthenticate
API CI/CD / Validate (composer + pint) (push) Successful in 2m7s
API CI/CD / Test (PHPUnit) (push) Failing after 2m17s
API CI/CD / Build frontend assets (push) Successful in 2m13s
API CI/CD / Security audit (push) Successful in 32s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
API CI/CD / Validate (composer + pint) (push) Successful in 2m7s
API CI/CD / Test (PHPUnit) (push) Failing after 2m17s
API CI/CD / Build frontend assets (push) Successful in 2m13s
API CI/CD / Security audit (push) Successful in 32s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
The TeacherPortalAuthenticate middleware called Auth::guard('sanctum')
without a try-catch, unlike MultiAuth and EnsurePrintRequestsAdminAccess
which already handle the InvalidArgumentException gracefully when the
sanctum guard driver is not yet registered.
This caused 'Auth guard [sanctum] is not defined' errors in tests when
the SanctumServiceProvider's driver registration hadn't completed before
middleware execution.
This commit is contained in:
@@ -22,7 +22,11 @@ class TeacherPortalAuthenticate
|
|||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sanctumUser = Auth::guard('sanctum')->user();
|
try {
|
||||||
|
$sanctumUser = Auth::guard('sanctum')->user();
|
||||||
|
} catch (\InvalidArgumentException) {
|
||||||
|
$sanctumUser = null;
|
||||||
|
}
|
||||||
if ($sanctumUser) {
|
if ($sanctumUser) {
|
||||||
Auth::setUser($sanctumUser);
|
Auth::setUser($sanctumUser);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user