update
This commit is contained in:
@@ -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()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user