Skip to content

Simplify API Client and fix token expiry issue - #29

Merged
anandani4136 merged 3 commits into
mainfrom
auth-fix
Aug 7, 2025
Merged

Simplify API Client and fix token expiry issue#29
anandani4136 merged 3 commits into
mainfrom
auth-fix

Conversation

@J164

@J164 J164 commented Aug 1, 2025

Copy link
Copy Markdown
Member

No description provided.

@J164
J164 requested review from a team and Copilot August 1, 2025 03:01
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 1, 2025

Copy link
Copy Markdown

Deploying rp-web-hype with  Cloudflare Pages  Cloudflare Pages

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

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 1, 2025

Copy link
Copy Markdown

Deploying rp-web-admin with  Cloudflare Pages  Cloudflare Pages

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

View logs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 createApi with a singleton api instance that uses configuration from a central Config object
  • Updated token expiry handling to automatically redirect to /auth/refresh instead of requiring callback functions
  • Introduced a new getRequireAuth utility 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

Comment thread shared/src/api/api.ts
Comment thread shared/src/components/RequireAuth.tsx
Comment thread shared/src/components/RequireAuth.tsx
Comment thread apps/sponsor/src/App.tsx
Comment thread shared/src/api/api.ts Outdated
anandani4136
anandani4136 previously approved these changes Aug 6, 2025

@anandani4136 anandani4136 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant, this was a much-needed refactor that really makes best use of our new monorepo structure. LGTM

miguelaenlle
miguelaenlle previously approved these changes Aug 6, 2025

@miguelaenlle miguelaenlle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@miguelaenlle
miguelaenlle dismissed stale reviews from anandani4136 and themself via 98dc182 August 6, 2025 11:38
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 6, 2025

Copy link
Copy Markdown

Deploying rp-web-sponsor with  Cloudflare Pages  Cloudflare Pages

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

View logs

@anandani4136
anandani4136 merged commit 4f94fac into main Aug 7, 2025
6 checks passed
@anandani4136
anandani4136 deleted the auth-fix branch August 7, 2025 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants