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

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:
root
2026-06-24 02:33:06 -04:00
parent baa6fff459
commit 36101b78d3
@@ -22,7 +22,11 @@ class TeacherPortalAuthenticate
return $next($request);
}
$sanctumUser = Auth::guard('sanctum')->user();
try {
$sanctumUser = Auth::guard('sanctum')->user();
} catch (\InvalidArgumentException) {
$sanctumUser = null;
}
if ($sanctumUser) {
Auth::setUser($sanctumUser);