[PR #373] [MERGED] Require authenticated user identity for billing APIs and remove localStorage fallback #681

Closed
opened 2026-03-13 21:03:27 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/AJaySi/ALwrity/pull/373
Author: @AJaySi
Created: 3/4/2026
Status: Merged
Merged: 3/5/2026
Merged by: @AJaySi

Base: mainHead: codex/refactor-billingservice-to-use-authenticated-user


📝 Commits (1)

  • 5a7b9e6 Refactor billing flows to require authenticated user IDs

📊 Changes

7 files changed (+54 additions, -33 deletions)

View changed files

📝 frontend/src/components/billing/CompactBillingDashboard/hooks/useCompactBillingData.ts (+1 -1)
📝 frontend/src/components/billing/CompactBillingDashboard/index.tsx (+1 -1)
📝 frontend/src/components/billing/EnhancedBillingDashboard.tsx (+25 -9)
📝 frontend/src/components/billing/SubscriptionRenewalHistory.tsx (+1 -1)
📝 frontend/src/hooks/useOAuthTokenAlerts.ts (+3 -4)
📝 frontend/src/pages/BillingPage.tsx (+11 -5)
📝 frontend/src/services/billingService.ts (+12 -12)

📄 Description

Motivation

  • Stop reading localStorage.getItem('user_id') and remove the 'demo-user' fallback so billing calls always use a canonical authenticated identity.
  • Prevent anonymous/optional user-id behavior across billing UI and hooks by enforcing explicit authenticated userId propagation.
  • Make it possible to migrate safely to backend /me/* style routes or otherwise rely solely on the server-resolved identity from the auth token.

Description

  • Updated frontend/src/services/billingService.ts so all user-scoped methods require an explicit userId parameter and no longer read localStorage or fall back to 'demo-user' (examples: getDashboardData, getUsageStats, getUsageTrends, getUsageAlerts, getUserSubscription, getRenewalHistory).
  • Adjusted dashboard consumers to pass authenticated identity: EnhancedBillingDashboard now imports useAuth, resolves effectiveUserId (prop or clerk userId), guards fetches when missing, and passes effectiveUserId to child components and billing calls.
  • Tightened component/hook contracts to accept required userId: changed useCompactBillingData hook signature and CompactBillingDashboard/SubscriptionRenewalHistory props to require userId and updated call sites accordingly.
  • Updated background polling hook useOAuthTokenAlerts to use the provided authenticated userId and skip polling when no authenticated identity is available (removed localStorage fallback).

Testing

  • Attempted a frontend build with npm --prefix frontend run build to validate compilation, but it failed in this environment due to missing dev dependencies (react-scripts: not found).
  • No automated unit tests were executed in CI from this environment; changes were validated by running repository-wide search/replace checks and manual inspection of affected call sites to ensure userId is passed through.

Codex Task


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/AJaySi/ALwrity/pull/373 **Author:** [@AJaySi](https://github.com/AJaySi) **Created:** 3/4/2026 **Status:** ✅ Merged **Merged:** 3/5/2026 **Merged by:** [@AJaySi](https://github.com/AJaySi) **Base:** `main` ← **Head:** `codex/refactor-billingservice-to-use-authenticated-user` --- ### 📝 Commits (1) - [`5a7b9e6`](https://github.com/AJaySi/ALwrity/commit/5a7b9e6c6bffc03c5713a433d577c446744120cb) Refactor billing flows to require authenticated user IDs ### 📊 Changes **7 files changed** (+54 additions, -33 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/components/billing/CompactBillingDashboard/hooks/useCompactBillingData.ts` (+1 -1) 📝 `frontend/src/components/billing/CompactBillingDashboard/index.tsx` (+1 -1) 📝 `frontend/src/components/billing/EnhancedBillingDashboard.tsx` (+25 -9) 📝 `frontend/src/components/billing/SubscriptionRenewalHistory.tsx` (+1 -1) 📝 `frontend/src/hooks/useOAuthTokenAlerts.ts` (+3 -4) 📝 `frontend/src/pages/BillingPage.tsx` (+11 -5) 📝 `frontend/src/services/billingService.ts` (+12 -12) </details> ### 📄 Description ### Motivation - Stop reading `localStorage.getItem('user_id')` and remove the `'demo-user'` fallback so billing calls always use a canonical authenticated identity. - Prevent anonymous/optional user-id behavior across billing UI and hooks by enforcing explicit authenticated `userId` propagation. - Make it possible to migrate safely to backend `/me/*` style routes or otherwise rely solely on the server-resolved identity from the auth token. ### Description - Updated `frontend/src/services/billingService.ts` so all user-scoped methods require an explicit `userId` parameter and no longer read `localStorage` or fall back to `'demo-user'` (examples: `getDashboardData`, `getUsageStats`, `getUsageTrends`, `getUsageAlerts`, `getUserSubscription`, `getRenewalHistory`). - Adjusted dashboard consumers to pass authenticated identity: `EnhancedBillingDashboard` now imports `useAuth`, resolves `effectiveUserId` (prop or clerk `userId`), guards fetches when missing, and passes `effectiveUserId` to child components and billing calls. - Tightened component/hook contracts to accept required `userId`: changed `useCompactBillingData` hook signature and `CompactBillingDashboard`/`SubscriptionRenewalHistory` props to require `userId` and updated call sites accordingly. - Updated background polling hook `useOAuthTokenAlerts` to use the provided authenticated `userId` and skip polling when no authenticated identity is available (removed `localStorage` fallback). ### Testing - Attempted a frontend build with `npm --prefix frontend run build` to validate compilation, but it failed in this environment due to missing dev dependencies (`react-scripts: not found`). - No automated unit tests were executed in CI from this environment; changes were validated by running repository-wide search/replace checks and manual inspection of affected call sites to ensure `userId` is passed through. ------ [Codex Task](https://chatgpt.com/codex/tasks/task_e_69a84685b1ec83288c28e9d4cdd60a8f) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-13 21:03:27 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ALwrity#681
No description provided.