Skip to content

Commit 68e6ed8

Browse files
committed
Use server reads for rate limit counts
1 parent fda665b commit 68e6ed8

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/lib/rate-limit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { doc, getDoc, increment, setDoc } from 'firebase/firestore';
1+
import { doc, getDocFromServer, increment, setDoc } from 'firebase/firestore';
22
import { getDb } from './db';
33

44
interface RateLimitOptions {
@@ -36,7 +36,7 @@ export async function enforceRateLimit(
3636
{ merge: true },
3737
);
3838

39-
const snapshot = await getDoc(ref);
39+
const snapshot = await getDocFromServer(ref);
4040
const data = snapshot.data() as RateLimitDocument | undefined;
4141
const count = data?.count ?? 0;
4242
const remaining = Math.max(0, maxRequests - count);

0 commit comments

Comments
 (0)