fix(auth): implement toast notifications and resolve connection issue…#41
Conversation
|
@atmihaa-06 is attempting to deploy a commit to the karan3431's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Great work on the routing and extracting the handleResponse logic! However, there's one issue left: you added the try/catch block to catch network TypeErrors inside apiFetch, but you forgot to wrap the raw fetch calls inside submitScan and getGradcam in a try/catch as well. If the backend drops during an image upload, fetch will throw an exception before it ever reaches your handleResponse, which will cause an unhandled rejection without a toast. Could you please extract the try/catch logic into a reusable wrapper, or make sure all raw fetch calls in api.ts are wrapped so that ECONNREFUSED is caught everywhere? |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Thanks for the feedback! I've refactored the API layer to centralize error handling as suggested. Here’s a summary of the changes: Created safeFetch: I moved the network-level try/catch logic into a reusable safeFetch wrapper, ensuring that any connection-related exceptions (like TypeError for ECONNREFUSED) are caught in one place. Refactored apiFetch: apiFetch now calls safeFetch internally, maintaining consistent error handling for all JSON-based requests. Updated submitScan & getGradcam: I refactored these methods to use safeFetch instead of raw fetch calls. This ensures that the FormData requests now properly trigger the toast notification and handle connection drops, preventing unhandled rejections. |
jpdevhub
left a comment
There was a problem hiding this comment.
Thanks for contributing the code is clean, robust and satisfies all the contraints given.
|
Just one quick housekeeping thing before we merge: could you edit the PR description and add the text Closes #12 anywhere in the body. This helps GitHub auto-close the issue for us. |
|
Done! You can merge the PR now. Thank you so much |
|
Can I know when this will be merged? |
There was a problem hiding this comment.
1 issue found across 6 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/main.tsx">
<violation number="1" location="src/main.tsx:10">
P1: Unprotected top-level `initTheme()` call can crash app startup on exceptions</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
| import { initTheme } from './lib/theme'; | ||
|
|
||
| // Initialize theme before rendering the app to prevent flicker | ||
| initTheme(); |
There was a problem hiding this comment.
P1: Unprotected top-level initTheme() call can crash app startup on exceptions
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/main.tsx, line 10:
<comment>Unprotected top-level `initTheme()` call can crash app startup on exceptions</comment>
<file context>
@@ -4,6 +4,10 @@ import posthog from 'posthog-js'
+import { initTheme } from './lib/theme';
+
+// Initialize theme before rendering the app to prevent flicker
+initTheme();
// PostHog is only initialized when the key is present.
</file context>
| initTheme(); | |
| try { | |
| initTheme(); | |
| } catch { | |
| // Silently degrade if theme init fails — avoids a blank screen. | |
| } |
|
why you have push another pr in this branch ? |
|
Sorry for that, that was by mistake. I have changed it. |
|
It will be merged when the SSoC website will be live and fully functional. As of know 1 june is the starting date. |
|
hey! since its june 1st today, hoping that you will merge the PR. |
3b63ba1 to
95f51cc
Compare
|
hehe i said i will merge means i will merge. Dont forget to star the repo and looking forward for more contributions ! |
Description
This PR addresses critical issues regarding backend connectivity and user-facing error states during authentication, specifically closing SYS-01: Replace Blank Screen with Toast Notifications for Connection Failures.
Key Changes
Backend Environment Setup: Created and configured backend/.env to ensure the Python API correctly recognizes environment variables and binds to the appropriate port.
Server Initialization: Standardized backend startup using uvicorn, ensuring the API correctly loads required ML models and listens for requests on port 8000.
Frontend Error Resilience: Updated AuthPage.tsx to include try/catch logic and loading state management (idle | processing | error). This ensures that if the backend is unreachable, the application displays a professional error notification rather than failing silently or showing a broken interface.
OAuth Flow Improvements: Refactored handleGoogleLogin to utilize explicit window.location.href navigation, ensuring a reliable handshake between the frontend and the authentication server.
Verification Results
Backend Stability: Confirmed Application startup complete on port 8000 via Uvicorn.
Connection Resilience: Successfully validated that a Failed to fetch error (e.g., when the backend is offline) triggers the toast notification and updates the UI status to error, preventing a blank screen.
UI/UX: The application now provides clear visual feedback during authentication attempts.
Evidence:
Closes #12
Summary by cubic
Show toast notifications for auth and API errors and centralize network/HTTP handling with a
safeFetchwrapper to avoid blank screens and connection failures. Added a globalToasterusingreact-hot-toastand a dark/light theme toggle with saved preference; completes SYS-01.Bug Fixes
safeFetchandhandleResponseinsrc/lib/api.tsto standardize 4xx/5xx handling and show toasts for server/network errors; applied toapiFetch,submitScan, andgetGradcam.src/pages/AuthPage.tsxwith full-page navigation, try/catch, and clearer "AUTH_INITIATED" messaging; handles query param errors without flicker.react-hot-toast, added a globalToasterinsrc/App.tsx, and a catch-all*route withsrc/pages/NotFound.tsx.New Features
toggleThemeandinitTheme, CSS variables, early init, and a navbar toggle; persisted inlocalStorageto prevent flicker.Written for commit 95f51cc. Summary will update on new commits.