diff --git a/popup/src/lib/leetpush.api.ts b/popup/src/lib/leetpush.api.ts index 4272a5b..e2c498e 100644 --- a/popup/src/lib/leetpush.api.ts +++ b/popup/src/lib/leetpush.api.ts @@ -25,7 +25,10 @@ export const fetchDailyProblem = async (): Promise => { * @returns The user stats **/ export const fetchUserStats = async (username: string): Promise => { - const response = await fetch(`${BASE_URL}/${username}`); + const normalizedUsername = username.trim(); + const response = await fetch( + `${BASE_URL}/${encodeURIComponent(normalizedUsername)}`, + ); if (response.status === 404) throw new Error("User not found"); else if (!response.ok) throw new Error("Failed to fetch user stats"); @@ -40,8 +43,12 @@ export const fetchUserStats = async (username: string): Promise => { export const fetchUserStreak = async ( username: string, ): Promise => { - const response = await fetch(`${BASE_URL}/userProfileCalendar/${username}`); + const normalizedUsername = username.trim(); + const response = await fetch( + `${BASE_URL}/userProfileCalendar/${encodeURIComponent(normalizedUsername)}`, + ); + if (response.status === 404) throw new Error("User not found"); if (!response.ok) throw new Error("Failed to fetch user streak"); return await response.json(); -}; +}; \ No newline at end of file