From 9661699d196527c92747aaf6ca85d816a965ab0f Mon Sep 17 00:00:00 2001 From: Kashvi Garg <97344852+kashvigarg@users.noreply.github.com> Date: Sat, 29 Mar 2025 16:38:22 +0000 Subject: [PATCH 1/6] Updated NextJS Params Consumption Structure --- web2/app/profile/[username]/page.tsx | 10 +++++++--- web2/app/prose/[proseId]/page.tsx | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/web2/app/profile/[username]/page.tsx b/web2/app/profile/[username]/page.tsx index b194de9..e618223 100644 --- a/web2/app/profile/[username]/page.tsx +++ b/web2/app/profile/[username]/page.tsx @@ -4,8 +4,12 @@ import { MainLayout } from "@/components/main-layout" import { UserProfile } from "@/components/user-profile" import { getUserProfile } from "@/lib/api" -export default async function ProfilePage(props: { params: Promise<{ username: string }> }) { - const params = await props.params; +export default async function ProfilePage({ + params, +}: { + params: Promise<{ username: string }> +}) { + const {username} = await params; const cookieStore = await cookies() const token = cookieStore.get("auth_token") @@ -13,7 +17,7 @@ export default async function ProfilePage(props: { params: Promise<{ username: s redirect("/login") } - const userData = await getUserProfile(params.username, token.value) + const userData = await getUserProfile(username, token.value) return ( diff --git a/web2/app/prose/[proseId]/page.tsx b/web2/app/prose/[proseId]/page.tsx index 04a16c8..7f1233a 100644 --- a/web2/app/prose/[proseId]/page.tsx +++ b/web2/app/prose/[proseId]/page.tsx @@ -4,8 +4,8 @@ import { MainLayout } from "@/components/main-layout" import { ProseDetail } from "@/components/prose-detail" import { getProseById } from "@/lib/api" -export default async function ProsePage(props: { params: Promise<{ proseId: string }> }) { - const params = await props.params; +export default async function ProsePage({params,}: { params: Promise<{ proseId: string }> }) { + const {proseId} = await params; const cookieStore = await cookies() const token = cookieStore.get("auth_token") @@ -13,7 +13,7 @@ export default async function ProsePage(props: { params: Promise<{ proseId: stri redirect("/login") } - const proseData = await getProseById(params.proseId, token.value) + const proseData = await getProseById(proseId, token.value) return ( From 94b67aa8fb9c7673c9bf5bc5966dc1d32098c592 Mon Sep 17 00:00:00 2001 From: Kashvi Garg <97344852+kashvigarg@users.noreply.github.com> Date: Sun, 30 Mar 2025 22:07:55 +0000 Subject: [PATCH 2/6] Updated User Profile Prose --- web2/app/api/[...path]/route.ts | 119 +++++++++++++++++++------------ web2/components/user-profile.tsx | 14 ++-- 2 files changed, 80 insertions(+), 53 deletions(-) diff --git a/web2/app/api/[...path]/route.ts b/web2/app/api/[...path]/route.ts index 24124ff..51d7c71 100644 --- a/web2/app/api/[...path]/route.ts +++ b/web2/app/api/[...path]/route.ts @@ -2,14 +2,13 @@ import { type NextRequest, NextResponse } from "next/server" // This is a proxy API route that forwards requests to the backend export async function GET(request: NextRequest, { params }: { params: { path: string[] } }) { - // const path = params.path.join("/") const url = new URL(request.url); const path = url.pathname.replace("/api/", ""); - const { searchParams } = new URL(request.url) - const token = searchParams.get("token") || request.headers.get("Authorization")?.split(" ")[1] + const { searchParams } = new URL(request.url); + const token = searchParams.get("token") || request.headers.get("Authorization")?.split(" ")[1]; // Check if this is an SSE endpoint - const isSSE = path === "timeline" || path === "notifications" || path.includes("/comments") + const isSSE = path === "timeline" || path === "notifications" || path.includes("/comments"); if (isSSE) { try { @@ -19,45 +18,68 @@ export async function GET(request: NextRequest, { params }: { params: { path: st Authorization: `Bearer ${token}`, Accept: "text/event-stream", }, - }) - - if (response.ok) { - // Set up SSE response - const encoder = new TextEncoder() - const stream = new ReadableStream({ - async start(controller) { - const data = await response.json() - - // Send the initial data - controller.enqueue(encoder.encode(`data: ${JSON.stringify(data)}\n\n`)) - - // Keep the connection open - const interval = setInterval(() => { - controller.enqueue(encoder.encode(": keepalive\n\n")) - }, 30000) - - // Clean up on close - request.signal.addEventListener("abort", () => { - clearInterval(interval) - controller.close() - }) - }, - }) - - return new NextResponse(stream, { - headers: { - "Content-Type": "text/event-stream", - "Cache-Control": "no-cache", - Connection: "keep-alive", - }, - }) + }); + + const text = await response.text(); + + if (response.ok && text.trim()) { + try { + const data = JSON.parse(text); + + // Set up SSE response + const encoder = new TextEncoder(); + const stream = new ReadableStream({ + async start(controller) { + controller.enqueue(encoder.encode(`data: ${JSON.stringify(data)}\n\n`)); + + // Keep the connection open + const interval = setInterval(() => { + controller.enqueue(encoder.encode(": keepalive\n\n")); + }, 30000); + + // Clean up on close + request.signal.addEventListener("abort", () => { + clearInterval(interval); + controller.close(); + }); + }, + }); + + return new NextResponse(stream, { + headers: { + "Content-Type": "text/event-stream", + "Cache-Control": "no-cache", + Connection: "keep-alive", + }, + }); + } catch (jsonError) { + console.error("SSE JSON parse error:", jsonError); + return NextResponse.json({ error: "Invalid JSON response from SSE" }, { status: 502 }); + } } else { - // Fall back to regular response - return NextResponse.json(await response.json(), { status: response.status }) + console.log("SSE response empty, falling back to basic fetch..."); + + const fallbackResponse = await fetch(`${process.env.API_URL}/api/${path}`, { + headers: { Authorization: `Bearer ${token}` }, + }); + + const fallbackText = await fallbackResponse.text(); + + if (!fallbackText.trim()) { + return NextResponse.json({ error: "Empty response from server" }, { status: 502 }); + } + + try { + return NextResponse.json(JSON.parse(fallbackText), { status: fallbackResponse.status }); + } catch { + return NextResponse.json({ error: "Invalid JSON from fallback" }, { status: 502 }); + } + } + } catch (error: any) { + console.error("SSE error:", error); + if (error.code !== "UND_ERR_HEADERS_TIMEOUT") { + return NextResponse.json({ error: "Failed to connect to SSE" }, { status: 500 }); } - } catch (error) { - console.error("SSE error:", error) - return NextResponse.json({ error: "Failed to connect to SSE" }, { status: 500 }) } } @@ -68,13 +90,18 @@ export async function GET(request: NextRequest, { params }: { params: { path: st Authorization: token ? `Bearer ${token}` : "", "Content-Type": request.headers.get("Content-Type") || "application/json", }, - }) + }); - const data = await response.json() - return NextResponse.json(data, { status: response.status }) + const text = await response.text(); // Read response as text + + if (!text.trim()) { + return NextResponse.json({ error: "Empty response from API" }, { status: 502 }); + } + + return NextResponse.json(JSON.parse(text), { status: response.status }); } catch (error) { - console.error("API error:", error) - return NextResponse.json({ error: "Failed to fetch data" }, { status: 500 }) + console.error("API error:", error); + return NextResponse.json({ error: "Failed to fetch data" }, { status: 500 }); } } diff --git a/web2/components/user-profile.tsx b/web2/components/user-profile.tsx index 83f8b3e..d94c990 100644 --- a/web2/components/user-profile.tsx +++ b/web2/components/user-profile.tsx @@ -37,8 +37,8 @@ type UserProfileProps = { export function UserProfile({ user: initialUser }: UserProfileProps) { const [user, setUser] = useState(initialUser); - // const [proses, setProses] = useState([]); - const proses: Array = [] + const [proses, setProses] = useState([]); + // const proses: Array = [] const [isLoading, setIsLoading] = useState(false); const { user: currentUser, token } = useAuth(); const [error, setError] = useState(null); @@ -64,7 +64,7 @@ export function UserProfile({ user: initialUser }: UserProfileProps) { } const data = await response.json(); - // setProses(data); + setProses(data.map((p: Prose) => ({ ...p, username: p.username || user.username }))); } catch (err) { setError("Failed to load prose. Please try again."); toast({ @@ -130,9 +130,9 @@ export function UserProfile({ user: initialUser }: UserProfileProps) { const result = await response.json(); - // setProses(proses.map(prose => - // prose.id === proseId ? { ...prose, liked: result.liked, likes_count: result.likes_count } : prose - // )); + setProses(proses.map(prose => + prose.id === proseId ? { ...prose, liked: result.liked, likes_count: result.likes_count } : prose + )); } catch (err) { toast({ title: "Error", @@ -157,7 +157,7 @@ export function UserProfile({ user: initialUser }: UserProfileProps) { throw new Error("Failed to delete verse"); } - // setProses(proses.filter(prose => prose.id !== proseId)); + setProses(proses.filter(prose => prose.id !== proseId)); toast({ title: "Verse deleted", From be1951dfbd6c506df877f9b19ea27f6ed862696b Mon Sep 17 00:00:00 2001 From: Kashvi Garg <97344852+kashvigarg@users.noreply.github.com> Date: Mon, 31 Mar 2025 11:01:47 +0000 Subject: [PATCH 3/6] Fixed Notification Errors --- web2/components/notification-indicator.tsx | 9 ++++- web2/components/notifications-list.tsx | 44 +++++++++++++++------- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/web2/components/notification-indicator.tsx b/web2/components/notification-indicator.tsx index 2ea0308..247b7fe 100644 --- a/web2/components/notification-indicator.tsx +++ b/web2/components/notification-indicator.tsx @@ -37,8 +37,15 @@ export function NotificationIndicator({ className = "" }: NotificationIndicatorP }) if (response.ok) { - const data = await response.json() + const text = await response.text() + const data = JSON.parse(text) + if (data!=null){ setHasUnread(data.some((notification: any) => !notification.read)) + } else { + setHasUnread(false) + console.log("EMPTY") + console.log(data) + } } } catch (err) { console.error("Failed to check unread notifications", err) diff --git a/web2/components/notifications-list.tsx b/web2/components/notifications-list.tsx index 2329b5d..f7cc0e7 100644 --- a/web2/components/notifications-list.tsx +++ b/web2/components/notifications-list.tsx @@ -31,7 +31,10 @@ export function NotificationsList() { const { data, error: sseError } = useSSE("/api/notifications", token, { onMessage: (data) => { if (data) { - setNotifications(data) + if (data!=null){ + setNotifications(data)} else { + setNotifications([]) + } setIsLoading(false) } }, @@ -40,7 +43,10 @@ export function NotificationsList() { useEffect(() => { if (data) { - setNotifications(data) + if (data!=null){ + setNotifications(data)} else { + setNotifications([]) + } setIsLoading(false) } @@ -62,7 +68,10 @@ export function NotificationsList() { } const data = await response.json() - setNotifications(data) + if (data!=null){ + setNotifications(data)} else { + setNotifications([]) + } } catch (err) { toast({ title: "Error", @@ -88,12 +97,16 @@ export function NotificationsList() { } // Update all notifications as read - setNotifications( - notifications.map((notification) => ({ - ...notification, - read: true, - })), - ) + if (notifications!=null){ + setNotifications( + notifications.map((notification) => ({ + ...notification, + read: true, + })), + )} else { + setNotifications([]) + } + toast({ title: "Notifications marked as read", @@ -122,6 +135,7 @@ export function NotificationsList() { } // Update the notification as read + if (notifications!=null) { setNotifications( notifications.map((notification) => { if (notification.id === notificationId) { @@ -132,7 +146,9 @@ export function NotificationsList() { } return notification }), - ) + ) } else { + setNotifications([]) + } } catch (err) { toast({ title: "Error", @@ -215,13 +231,15 @@ export function NotificationsList() { Refresh + { notifications != null? ( + ) : (null)} - + - {notifications.length === 0 ? ( + {notifications!= null && notifications.length === 0 ? (

No notifications yet.

From c30a8a48121428d6e4b76e58ce5cc47b308fa551 Mon Sep 17 00:00:00 2001 From: Kashvi Garg <97344852+kashvigarg@users.noreply.github.com> Date: Mon, 31 Mar 2025 11:03:24 +0000 Subject: [PATCH 4/6] Updated Prose Object --- web2/components/prose-detail.tsx | 1 + web2/components/timeline.tsx | 42 ++++++++++++++------------------ web2/components/user-profile.tsx | 3 ++- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/web2/components/prose-detail.tsx b/web2/components/prose-detail.tsx index 44137b4..f53b178 100644 --- a/web2/components/prose-detail.tsx +++ b/web2/components/prose-detail.tsx @@ -37,6 +37,7 @@ export function ProseDetail({ prose: initialProse }: ProseDetailProps) { headers: { Authorization: `Bearer ${token}`, }, + body: JSON.stringify("") }) if (!response.ok) { diff --git a/web2/components/timeline.tsx b/web2/components/timeline.tsx index 74632dc..3da61a7 100644 --- a/web2/components/timeline.tsx +++ b/web2/components/timeline.tsx @@ -35,34 +35,29 @@ export function Timeline() { const [error, setError] = useState(null); const { toast } = useToast(); - // Try to use SSE for timeline, fall back to regular fetch + // Use SSE to get timeline updates const { data, error: sseError } = useSSE("/api/timeline", token, { - onMessage: (data) => { - if (data) { - setTimelineItems(data); + onMessage: (newData) => { + if (newData && newData.length > 0) { + setTimelineItems(newData); setIsLoading(false); } }, fallbackToFetch: true, }); + // Fetch timeline if SSE fails useEffect(() => { - refreshTimeline(); // Ensure data is fetched when the page loads - }, []); - - useEffect(() => { - if (data) { + if (sseError || !data || data.length === 0) { + fetchTimeline(); + } else { setTimelineItems(data); setIsLoading(false); } - - if (sseError) { - setError("Failed to load timeline. Please try again."); - setIsLoading(false); - } }, [data, sseError]); - const refreshTimeline = async () => { + // Fetch timeline function + const fetchTimeline = async () => { console.log("TIMELINE CALL"); setIsLoading(true); setError(null); @@ -73,17 +68,15 @@ export function Timeline() { Authorization: `Bearer ${token}`, }, }); - console.log("RESPONSE") - console.log(response) if (!response.ok) { throw new Error("Failed to refresh timeline"); } - const data = await response.json(); - console.log("DATA") - console.log(data); - setTimelineItems(data); + const responseData = await response.json(); + console.log("DATA:", responseData); + + setTimelineItems(responseData); } catch (err) { setError("Failed to refresh timeline. Please try again."); toast({ @@ -96,6 +89,7 @@ export function Timeline() { } }; + // Handle like toggles const handleLikeToggle = async (proseId: string) => { try { const response = await fetch(`/api/prose/${proseId}/togglelike`, { @@ -111,7 +105,7 @@ export function Timeline() { const result = await response.json(); - // Update the prose in the list + // Update the liked state in the timeline setTimelineItems( timelineItems.map((item) => { if (item.prose.id === proseId) { @@ -140,7 +134,7 @@ export function Timeline() {

Your Timeline

- @@ -169,7 +163,7 @@ export function Timeline() { {error} - diff --git a/web2/components/user-profile.tsx b/web2/components/user-profile.tsx index d94c990..f6affff 100644 --- a/web2/components/user-profile.tsx +++ b/web2/components/user-profile.tsx @@ -122,6 +122,7 @@ export function UserProfile({ user: initialUser }: UserProfileProps) { headers: { Authorization: `Bearer ${token}`, }, + body: JSON.stringify("") }); if (!response.ok) { @@ -214,7 +215,7 @@ export function UserProfile({ user: initialUser }: UserProfileProps) { Verses - Likes + {/* Likes */} From b2b3d0b6adb0e54f0be5f812e00939951915bcec Mon Sep 17 00:00:00 2001 From: Kashvi Garg <97344852+kashvigarg@users.noreply.github.com> Date: Tue, 1 Apr 2025 16:37:52 +0000 Subject: [PATCH 5/6] Untested Changes --- web2/components/comments-list.tsx | 6 ++- web2/components/notifications-list.tsx | 49 ++++++++++---------- web2/components/timeline.tsx | 64 +++++++++++++++----------- web2/hooks/use-toast.ts | 2 +- web2/lib/auth-provider.tsx | 33 +++++++++---- web2/lib/use-sse.tsx | 18 +++++--- 6 files changed, 103 insertions(+), 69 deletions(-) diff --git a/web2/components/comments-list.tsx b/web2/components/comments-list.tsx index c0ae326..c41ff9c 100644 --- a/web2/components/comments-list.tsx +++ b/web2/components/comments-list.tsx @@ -37,6 +37,8 @@ export function CommentsList({ proseId }: { proseId: string }) { const { data, error: sseError } = useSSE(`/api/${proseId}/comments`, token, { onMessage: (data) => { if (data) { + console.log("SSE CHECK FOR COMMENTS") + console.log(data) setComments(data) setIsLoading(false) } @@ -68,6 +70,7 @@ export function CommentsList({ proseId }: { proseId: string }) { } const data = await response.json() + console.log(data) setComments(data) } catch (err) { toast({ @@ -116,7 +119,7 @@ export function CommentsList({ proseId }: { proseId: string }) { }) } } - + console.log(comments) if (isLoading) { return (
@@ -144,6 +147,7 @@ export function CommentsList({ proseId }: { proseId: string }) { ) } + return (
{comments.map((comment) => ( diff --git a/web2/components/notifications-list.tsx b/web2/components/notifications-list.tsx index f7cc0e7..6513588 100644 --- a/web2/components/notifications-list.tsx +++ b/web2/components/notifications-list.tsx @@ -31,6 +31,8 @@ export function NotificationsList() { const { data, error: sseError } = useSSE("/api/notifications", token, { onMessage: (data) => { if (data) { + console.log("SSE CHECK FOR NOTIFS") + console.log(data) if (data!=null){ setNotifications(data)} else { setNotifications([]) @@ -69,7 +71,7 @@ export function NotificationsList() { const data = await response.json() if (data!=null){ - setNotifications(data)} else { + setNotifications(data.filter((notification: Notification) => !notification.read));} else { setNotifications([]) } } catch (err) { @@ -83,6 +85,10 @@ export function NotificationsList() { } } + const removeNotification = (notificationId: string) => { + setNotifications((prev) => prev.filter((n) => n.id !== notificationId)); + }; + const markAllAsRead = async () => { try { const response = await fetch("/api/notifications/mark_as_read", { @@ -90,22 +96,25 @@ export function NotificationsList() { headers: { Authorization: `Bearer ${token}`, }, + body: JSON.stringify("") }) + console.log(response) + if (!response.ok) { throw new Error("Failed to mark notifications as read") } // Update all notifications as read - if (notifications!=null){ - setNotifications( - notifications.map((notification) => ({ - ...notification, - read: true, - })), - )} else { + // if (notifications!=null){ + // setNotifications( + // notifications.map((notification) => ({ + // ...notification, + // read: true, + // })), + // )} else { setNotifications([]) - } + // } toast({ @@ -113,6 +122,7 @@ export function NotificationsList() { description: "All notifications have been marked as read", }) } catch (err) { + console.log(err) toast({ title: "Error", description: "Failed to mark notifications as read", @@ -128,27 +138,15 @@ export function NotificationsList() { headers: { Authorization: `Bearer ${token}`, }, + body: JSON.stringify("") }) - + console.log(response) if (!response.ok) { throw new Error("Failed to mark notification as read") } // Update the notification as read - if (notifications!=null) { - setNotifications( - notifications.map((notification) => { - if (notification.id === notificationId) { - return { - ...notification, - read: true, - } - } - return notification - }), - ) } else { - setNotifications([]) - } + removeNotification(notificationId) } catch (err) { toast({ title: "Error", @@ -189,7 +187,7 @@ export function NotificationsList() { return ( <> {actorText} - {" commented on your verse"} + {" commented on your prose"} ) case "follow": @@ -245,6 +243,7 @@ export function NotificationsList() {
) : ( notifications.map((notification) => ( + ([]); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); @@ -37,27 +35,37 @@ export function Timeline() { // Use SSE to get timeline updates const { data, error: sseError } = useSSE("/api/timeline", token, { - onMessage: (newData) => { - if (newData && newData.length > 0) { - setTimelineItems(newData); + onMessage: (data) => { + if (data) { + console.log("SSE CHECK FOR TL") + console.log(data) + if (data!=null){ + setTimelineItems(data); setIsLoading(false); + } } + console.log("SSE NO DATA FOR TL") }, fallbackToFetch: true, }); // Fetch timeline if SSE fails useEffect(() => { - if (sseError || !data || data.length === 0) { - fetchTimeline(); - } else { - setTimelineItems(data); - setIsLoading(false); + if (data) { + if (data!=null){ + setTimelineItems(data)} else { + setTimelineItems([]) + } + setIsLoading(false) + } + + if (sseError) { + fetchTimelineItems() } }, [data, sseError]); // Fetch timeline function - const fetchTimeline = async () => { + const fetchTimelineItems = async () => { console.log("TIMELINE CALL"); setIsLoading(true); setError(null); @@ -76,7 +84,11 @@ export function Timeline() { const responseData = await response.json(); console.log("DATA:", responseData); - setTimelineItems(responseData); + if (responseData!=null){ + setTimelineItems(responseData); + } else { + setTimelineItems([]) + } } catch (err) { setError("Failed to refresh timeline. Please try again."); toast({ @@ -134,7 +146,7 @@ export function Timeline() {

Your Timeline

- @@ -163,7 +175,7 @@ export function Timeline() { {error} - diff --git a/web2/hooks/use-toast.ts b/web2/hooks/use-toast.ts index 02e111d..0fdf258 100644 --- a/web2/hooks/use-toast.ts +++ b/web2/hooks/use-toast.ts @@ -182,7 +182,7 @@ function useToast() { listeners.splice(index, 1) } } - }, [state]) + }, []) return { ...state, diff --git a/web2/lib/auth-provider.tsx b/web2/lib/auth-provider.tsx index 3121524..024c47a 100644 --- a/web2/lib/auth-provider.tsx +++ b/web2/lib/auth-provider.tsx @@ -71,7 +71,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { } checkAuth() - }, []) + }, [user]) const refreshToken = async () => { try { @@ -213,17 +213,32 @@ function setCookie(name: string, value: string, days: number) { document.cookie = `${name}=${value};expires=${expires.toUTCString()};path=/` } -function getCookie(name: string) { - const nameEQ = name + "=" - const ca = document.cookie.split(";") - for (let i = 0; i < ca.length; i++) { - let c = ca[i] - while (c.charAt(0) === " ") c = c.substring(1, c.length) - if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length) +// function getCookie(name: string) { +// const nameEQ = name + "=" +// const ca = document.cookie.split(";") +// for (let i = 0; i < ca.length; i++) { +// let c = ca[i] +// while (c.charAt(0) === " ") c = c.substring(1, c.length) +// if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length) +// } +// return null +// } + +function getCookie(name: string): string | null { + const nameEQ = name + "="; + const cookies = document.cookie.split(";"); + + for (const cookie of cookies) { + const trimmedCookie = cookie.trim(); + if (trimmedCookie.startsWith(nameEQ)) { + return trimmedCookie.substring(nameEQ.length); + } } - return null + + return null; } + function deleteCookie(name: string) { document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/` } diff --git a/web2/lib/use-sse.tsx b/web2/lib/use-sse.tsx index 3c9b852..e7be8d2 100644 --- a/web2/lib/use-sse.tsx +++ b/web2/lib/use-sse.tsx @@ -29,14 +29,18 @@ export function useSSE(url: string, token: string | null, options: SSEOptions } eventSource.onmessage = (event) => { - try { - const parsedData = JSON.parse(event.data) - setData(parsedData) - options.onMessage?.(parsedData) - } catch (err) { - console.error("Error parsing SSE data", err) + if (event.data.startsWith("data:")) { + try { + const parsedData = JSON.parse(event.data.replace(/^data: /, "")); + setData(parsedData); + options.onMessage?.(parsedData); + } catch (err) { + console.error("Error parsing SSE data", err); + } + } else { + console.warn("Received non-SSE data", event.data); } - } + }; eventSource.onerror = (err) => { console.error("SSE error", err) From 4dbd7520352e3cfdceffe2afc1085e3d99e6a513 Mon Sep 17 00:00:00 2001 From: Kashvi Garg <97344852+kashvigarg@users.noreply.github.com> Date: Sat, 5 Apr 2025 19:40:28 +0000 Subject: [PATCH 6/6] Fixed api/users/ Dependency --- web2/lib/auth-provider.tsx | 3 ++- web2/lib/use-sse.tsx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/web2/lib/auth-provider.tsx b/web2/lib/auth-provider.tsx index 024c47a..52607ea 100644 --- a/web2/lib/auth-provider.tsx +++ b/web2/lib/auth-provider.tsx @@ -71,7 +71,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { } checkAuth() - }, [user]) + }, []) const refreshToken = async () => { try { @@ -163,6 +163,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { }) if (!response.ok) { + console.log(response) throw new Error("Signup failed") } diff --git a/web2/lib/use-sse.tsx b/web2/lib/use-sse.tsx index e7be8d2..35554f6 100644 --- a/web2/lib/use-sse.tsx +++ b/web2/lib/use-sse.tsx @@ -22,7 +22,7 @@ export function useSSE(url: string, token: string | null, options: SSEOptions const connectSSE = () => { try { // Try to use SSE - eventSource = new EventSource(`${url}?token=${token}`) + eventSource = new EventSource(`${url}?token=${token}&sse=true`) eventSource.onopen = () => { setIsConnected(true)