27 lines
647 B
PHP
27 lines
647 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
|
use Illuminate\Http\Request;
|
|
|
|
class Authenticate extends Middleware
|
|
{
|
|
protected function redirectTo(Request $request): ?string
|
|
{
|
|
if ($request->expectsJson() || $request->is('api/*')) {
|
|
return null;
|
|
}
|
|
// fallback to null to avoid calling route('login') which doesn't exist
|
|
return null;
|
|
}
|
|
|
|
protected function unauthenticated($request, array $guards)
|
|
{
|
|
throw new \Illuminate\Auth\AuthenticationException(
|
|
'Unauthenticated.',
|
|
$guards
|
|
);
|
|
}
|
|
}
|