feat(frontend): implement centralized axios API client and global 401 handling#142
Open
ranbeer06052009 wants to merge 7 commits into
Open
feat(frontend): implement centralized axios API client and global 401 handling#142ranbeer06052009 wants to merge 7 commits into
ranbeer06052009 wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors the frontend networking layer from raw fetch calls scattered across service files to a centralized axios instance (apiClient) with a request interceptor that injects the bearer token from localStorage and a response interceptor that clears auth state and redirects to /login on 401. Service signatures lose their token parameter, and that prop is removed throughout the component/hook tree.
Changes:
- Adds
apiClient.tswith request (token injection) and response (global 401 handling) interceptors; bumpsaxiosto^1.16.1. - Migrates
auth.service.ts,user.service.ts,interview.service.ts, andorganization.service.tsfromfetchtoapiClient, dropping thetokenargument on each function. - Removes
tokenprop drilling fromApp.tsx,DashboardPage,InterviewSessionPage,ProfileSetupPage,DsaPanel, and the corresponding hooks (useDashboard,useInterviewSession,useProfileSetup).
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/services/apiClient.ts | New axios instance with request/response interceptors for token injection and 401 redirect. |
| frontend/src/services/auth.service.ts | Switches loginUser/fetchCurrentUser to apiClient; keeps BASE_URL only for Google OAuth URL. |
| frontend/src/services/user.service.ts | Replaces fetch helpers with apiClient; drops token params. |
| frontend/src/services/interview.service.ts | Replaces fetch helpers with apiClient; drops token params on all DSA/session calls. |
| frontend/src/services/organization.service.ts | Replaces fetch with apiClient for org signup/login. |
| frontend/src/features/user/ProfileSetupPage.tsx | Removes token prop; converts component to function declaration. |
| frontend/src/features/user/hooks/useProfileSetup.ts | Drops token parameter and adjusts updateUserProfile calls. |
| frontend/src/features/user/hooks/useDashboard.ts | Drops token parameter and effect dependency; removes early-return guard. |
| frontend/src/features/user/DashboardPage.tsx | Removes token prop and threading into useDashboard. |
| frontend/src/features/interview/InterviewSessionPage.tsx | Removes token prop and removes it from renderRound/DsaPanel. |
| frontend/src/features/interview/hooks/useInterviewSession.ts | Drops token from hook signature and effect deps. |
| frontend/src/features/interview/components/DsaPanel.tsx | Removes token prop; simplifies DSA service call sites. |
| frontend/src/App.tsx | Removes token props passed down to pages; updates fetchCurrentUser call. |
| frontend/package.json, package-lock.json | Bumps axios to ^1.16.1 (pulls in https-proxy-agent, agent-base). |
Files not reviewed (1)
- frontend/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Author
|
@RITVIKKAMASETTY can you please rereview if any further changes needed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #137
@sathwikshetty33 This PR refactors the frontend network architecture by replacing raw
fetchcalls with a centralizedaxiosAPI client. It significantly reduces code duplication and improves security/UX by handling token expirations gracefully at a global level.Changes Made
axiosto handle HTTP requests.apiClient.ts:Authorization: Bearer <token>header into all outgoing API requests (prioritizingtokenthenorg_tokenfromlocalStorage).401 Unauthorizedresponses, clears stale authentication data, and safely redirects the user to the/loginpage.auth.service.ts,user.service.ts,interview.service.ts, andorganization.service.tsto useapiClientinstead offetch.tokenargument was safely removed from all service functions. Consequently, thetokenprop was cleanly removed from the entire React component tree (App.tsx,DashboardPage.tsx,InterviewSessionPage.tsx,ProfileSetupPage.tsx, etc.) and their respective hooks.Testing Performed
npm run build/tsc -b) with 0 errors.apiClientautomatically attaches the JWT header to outgoing requests./login.Type of Change