Simplify API Client and fix token expiry issue - #29
Conversation
Deploying rp-web-hype with
|
| Latest commit: |
98dc182
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://63809d82.rp-web-hype.pages.dev |
| Branch Preview URL: | https://auth-fix.rp-web-hype.pages.dev |
Deploying rp-web-admin with
|
| Latest commit: |
98dc182
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://6df67b59.rp-web-admin.pages.dev |
| Branch Preview URL: | https://auth-fix.rp-web-admin.pages.dev |
There was a problem hiding this comment.
Pull Request Overview
This PR simplifies the API client architecture by consolidating the createApi function into a singleton API instance and improves token expiry handling through automatic refresh redirects.
- Replaced the factory function
createApiwith a singletonapiinstance that uses configuration from a central Config object - Updated token expiry handling to automatically redirect to
/auth/refreshinstead of requiring callback functions - Introduced a new
getRequireAuthutility to simplify authentication wrapper setup for routes
Reviewed Changes
Copilot reviewed 40 out of 40 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| shared/src/api/api.ts | New singleton API instance replacing the factory pattern |
| shared/src/api/axios.ts | Removed factory function in favor of singleton approach |
| shared/src/utils/require-auth.tsx | New utility for creating authentication-wrapped routes |
| shared/src/components/RequireAuth.tsx | Refactored to remove API dependency and use singleton |
| shared/src/api/auth.ts | Simplified to use Config directly instead of passed clientId |
| apps/*/src/util/api.ts | Removed local API instances in favor of shared singleton |
| apps/*/src/App.tsx | Added refresh handlers and updated route protection |
anandani4136
left a comment
There was a problem hiding this comment.
Brilliant, this was a much-needed refactor that really makes best use of our new monorepo structure. LGTM
miguelaenlle
left a comment
There was a problem hiding this comment.
I looked through all the changes, and everything looks good apart from the linter errors. I also tested the sponsor site, which works as expected.
I was unable to test the admin site presumably because I haven't configured my account on the local database, but I'm assuming that this has already been tested.
98dc182
Deploying rp-web-sponsor with
|
| Latest commit: |
98dc182
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://3b4d5b18.rp-web-sponsor.pages.dev |
| Branch Preview URL: | https://auth-fix.rp-web-sponsor.pages.dev |
No description provided.