fix: server-validate restore receipts and scope form cache by userId#708
Merged
Conversation
…cache by userId (rinafcode#616) Issue rinafcode#615 – restorePurchases server validation - Each restored purchase is now POST'd to /payments/validate before updating subscription state. - Only purchases with validated: true update state; invalid receipts are logged and skipped. - _setTier is called for the most-recently-validated restored subscription. - Fixed stale log.error calls -> appLogger.errorSync throughout the service. Issue rinafcode#616 – useFormCache user-scoped cache key - Added getFormCacheStorageKey(userId) which returns `@teachlink/form-cache/${userId}/v1`. - All formCache functions now accept a storageKey parameter so data is isolated per user. - useFormCache reads userId from useAppStore and derives storageKey via useMemo; cache reloads automatically when userId changes (user switch). Tests - src/__tests__/services/mobilePayments.test.ts: valid/invalid receipt filtering, finishTransaction only for valid, tier update. - src/__tests__/services/formCache.test.ts: user-scoped key isolation. - Updated tests/services/formCache.test.ts and tests/hooks/useFormCache.test.ts to match new signatures. Closes rinafcode#615 Closes rinafcode#616
|
@authenticeasy-sys Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
…orm-cache-user-scope
Contributor
|
Thank you for contributing to the project. |
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.
Summary
Fixes two privacy/security bugs identified in issues #615 and #616.
Fix #615 — restorePurchases validates receipts server-side before updating state
Problem:
restorePurchases()calledRNIap.getAvailablePurchases()and mapped every result directly toPurchaseRecord, meaning a stale, cancelled, or refunded purchase could grant premium access.Changes to
src/services/mobilePayments.ts:/payments/validate-receiptbefore state update.valid: trueare added to the restored list and finished viafinishTransaction.appLogger.infoSyncand skipped._setTieris called for the most-recently-dated valid subscription.log.errorcalls →appLogger.errorSync.Fix #616 — useFormCache cache key is user-scoped
Problem: All users on the same device shared form data under a single storage key (
@teachlink/form-cache/v1), causing privacy leakage between users.Changes to
src/services/formCache.ts:getFormCacheStorageKey(userId)returning@teachlink/form-cache/${userId}/v1.loadFormCache,saveFormCache,getCachedFieldValues,cacheFormValues,setCachedFieldValue,clearFormCache) now takestorageKeyas their first parameter.Changes to
src/hooks/useFormCache.ts:userIdfromuseAppStorevia selector.storageKeywithuseMemoso it recomputes when the user changes.Tests
src/__tests__/services/mobilePayments.test.ts(new): 4 tests verifying valid/invalid receipt filtering,finishTransactiononly called for valid, and tier updated after restore.src/__tests__/services/formCache.test.ts(new): 6 tests verifying distinct user keys, correct read/write scoping, and that one user's data cannot bleed into another.tests/services/formCache.test.ts(updated): All assertions migrated to use the newstorageKeyparameter.tests/hooks/useFormCache.test.ts(updated): Store mocked to provideuserId;clearCacheassertion updated to expect the user-scoped key.Closes #615
Closes #616