Skip to content

Commit

Permalink
#28 fix: analyse
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhongit committed Dec 10, 2024
1 parent 09694a6 commit b4ebd06
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace CSlant\Blog\ApiPackage\Providers;

use CSlant\Blog\Core\Models\User;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
Expand All @@ -21,7 +22,11 @@ public function boot(): void
protected function configureRateLimiting(): void
{
RateLimiter::for((string) config('blog-api.defaults.route_prefix'), function (Request $request) {
return Limit::perMinute(40)->by(optional($request->user())->id ?: $request->ip());
/** @var User|null $user */
$user = $request->user();
$identifier = $user ? $user->id : $request->ip();

return Limit::perMinute(40)->by($identifier);
});
}
}

0 comments on commit b4ebd06

Please sign in to comment.