From c558e5ba40347dacb4a612337e04f444e1b048b9 Mon Sep 17 00:00:00 2001 From: Antigravity AI Date: Thu, 30 Apr 2026 17:33:09 +0530 Subject: [PATCH] fix(rateLimiter): await async checkRateLimit in getAllRateLimits + add SSR guard --- src/lib/rateLimiter.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib/rateLimiter.js b/src/lib/rateLimiter.js index fc5d0e09..8f6b689d 100644 --- a/src/lib/rateLimiter.js +++ b/src/lib/rateLimiter.js @@ -50,6 +50,16 @@ export async function checkRateLimit(walletAddress) { } // Fallback to legacy localStorage check for migration + // Guard against SSR environments where localStorage is not available + if (typeof localStorage === 'undefined') { + return { + canUpdate: true, + remainingTime: 0, + lastUpdate: null, + nextUpdateTime: null, + }; + } + const lastUpdateKey = `risk_score_last_update_${walletAddress}`; const lastUpdate = localStorage.getItem(lastUpdateKey); @@ -189,8 +199,10 @@ export async function clearRateLimit(walletAddress) { /** * Get all rate limited wallets (for debugging) */ -export function getAllRateLimits() { +export async function getAllRateLimits() { try { + if (typeof localStorage === 'undefined') return []; + const rateLimits = []; for (let i = 0; i < localStorage.length; i++) { @@ -198,7 +210,8 @@ export function getAllRateLimits() { if (key && key.startsWith("risk_score_last_update_")) { const walletAddress = key.replace("risk_score_last_update_", ""); const lastUpdate = parseInt(localStorage.getItem(key)); - const status = checkRateLimit(walletAddress); + // checkRateLimit is async — must be awaited to get the resolved value + const status = await checkRateLimit(walletAddress); rateLimits.push({ walletAddress,