mirror of
https://github.com/docmost/docmost.git
synced 2026-08-30 10:26:25 +08:00
14 lines
448 B
TypeScript
14 lines
448 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { ThrottlerGuard } from '@nestjs/throttler';
|
|
|
|
type AuthedRequest = { user?: { id?: string } };
|
|
|
|
@Injectable()
|
|
export class UserThrottlerGuard extends ThrottlerGuard {
|
|
protected async getTracker(req: AuthedRequest): Promise<string> {
|
|
const userId = req.user?.id;
|
|
if (userId) return `user:${userId}`;
|
|
return super.getTracker(req as Parameters<ThrottlerGuard['getTracker']>[0]);
|
|
}
|
|
}
|