Skip to content

Conversation

@aaudin90
Copy link
Collaborator

@aaudin90 aaudin90 commented Feb 7, 2026

Summary

Moves deviceId and userId ownership from ApphudInternal to UserRepository, eliminating state duplication and making UserRepository the single source of
truth for user identifiers.

Changes

  • Move deviceId ownership to UserRepository — deviceId is no longer stored as an ApphudInternal field; it is read/written via
    UserRepository.getDeviceId()/setDeviceId(). All consumers (RequestManager, PurchaseBodyFactory, RegistrationBodyFactory, RegistrationProvider) obtain
    deviceId through the repository
  • Move userId ownership to UserRepository — same for userId: removed field from ApphudInternal, added getUserId()/setUserId() to UserRepository. Public
    API Apphud.userId() delegates to the repository
  • Make setCurrentUser the single write point for userId — setCurrentUser() now automatically syncs userId when a new user is written, returning a flag
    indicating whether userId changed for listener notification
  • Replace redundant getCurrentUser().userId with getUserId() — removed 3 places where userId was read through an intermediate ApphudUser object instead
    of calling getUserId() directly

Result

  • ApphudInternal no longer owns deviceId/userId — only consumes them via UserRepository
  • Single write point for userId — setCurrentUser()
  • 14 files affected, net change: +68 / -69 lines

aaudin90 and others added 4 commits February 7, 2026 22:23
Remove deviceId variable from ApphudInternal, making UserRepository
the single source of truth. All access now goes through
userRepository.getDeviceId()/setDeviceId() which delegates to
UserDataSource (SharedPreferences).

Updated ServiceLocator to initialize userRepository before
RegistrationProvider and PurchaseBodyFactory, injecting it as
a dependency. Removed direct storage.deviceId access from
ApphudInternal.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Remove ApphudInternal.userId field and replace all references with
userRepository.getUserId()/setUserId(). This makes UserRepository the
single owner of userId state, consistent with the previous deviceId
migration.

Changes:
- Remove `userId` field from ApphudInternal
- Replace all ApphudInternal.userId reads with userRepository.getUserId()
- Replace all ApphudInternal.userId/storage.userId writes with
  userRepository.setUserId()
- Add getUserId()/setUserId() to RegistrationProvider for
  RegistrationBodyFactory access
- Update tests to use userRepository instead of ApphudInternal.userId

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…userId

Ensure userIdKey in SharedPreferences is always updated atomically when
setCurrentUser() is called, including for temporary (fallback) users.
Remove redundant userId side-effect from SharedPreferencesStorage.updateUser().

Previously userId was written from two places at different times, creating
a desync window (e.g. on crash between writes). Now:
- setCurrentUser() always calls dataSource.saveUserId(user.userId)
- SharedPreferencesStorage.updateUser() no longer writes userIdKey
- updateUserState() no longer needs a separate setUserId() call

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…getUserId()

Replaced 3 places where userId was read from ApphudUser object obtained
from userRepository with direct userRepository.getUserId() calls:
- trackAnalytics: eliminated getCurrentUser() call entirely
- updateUserId fallback chain: simplified getCurrentUser()?.userId
- tryWebAttribution: extracted currentUserId variable for two usages

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@aaudin90 aaudin90 force-pushed the RemoveDeviceIdUserId branch from 3ff608c to 23ec958 Compare February 7, 2026 19:23
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.

1 participant