This commit is contained in:
baodev0
2026-09-23 15:17:18 +07:00
parent cd38c5d6d0
commit 82a71244ca
107 changed files with 3332 additions and 3306 deletions
+13 -2
View File
@@ -62,8 +62,19 @@ class RouteServiceProvider extends ServiceProvider
{
RateLimiter::for('api', function (Request $request) {
// Admin SPA makes many parallel requests per page — use a higher limit for authenticated users
$limit = $request->user() ? 300 : 60;
return Limit::perMinute($limit)->by($request->user()?->id ?: $request->ip());
// Guard mặc định là admin → khách (JWT guard client) phải lấy riêng, nếu không mọi khách bị đếm theo IP.
$key = ($admin = $request->user()) ? 'admin:' . $admin->id
: (($client = $request->user('client')) ? 'client:' . $client->id : null);
return Limit::perMinute($key ? 300 : 60)->by($key ?: $request->ip());
});
// Auth endpoint của khách (login/verify/forgot...). portal-client gọi API từ Next server nên
// IP gần như luôn là IP của Next → khoá theo route + email, không theo IP (tránh chặn chung mọi khách).
RateLimiter::for('client-auth', function (Request $request) {
$email = strtolower(trim((string) $request->input('email')));
return Limit::perMinute(5)->by($request->route()?->getName() . '|' . ($email ?: $request->ip()));
});
}
}