直接访问 API 的处理

This commit is contained in:
Database Server 2022-11-07 09:13:40 +08:00
parent eaff62ea55
commit a1fd30d369
2 changed files with 23 additions and 1 deletions

View File

@ -2,8 +2,9 @@
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Auth\AuthenticationException;
class Handler extends ExceptionHandler
{
@ -47,4 +48,20 @@ public function register()
//
});
}
/**
* Convert an authentication exception into an unauthenticated response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}
return redirect()->guest(route('index'));
}
}

View File

@ -23,6 +23,11 @@ public function handle(Request $request, Closure $next, ...$guards)
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
// $user = $this->auth->guard($guard)->user();
// if ($user->banned_at) {
// return $this->forbidden('您已被封禁,原因是: ' . $user->banned_reason ?? '一次或多次触犯了我们的规则。');
// }
return redirect(RouteServiceProvider::HOME);
}
}