arch-atlas

Auth Storage Service

core/services/auth_storage.dart · SharedPreferences

data

Overview

Wraps SharedPreferences for everything session-shaped: customer + seller tokens, isLoggedIn flag, profileSetupComplete, ToS acceptance, pending seller registration, and per-(fcm,auth) tokens already synced to backend.

User Flow

  1. saveCustomerSession / saveSellerSession write token + isLoggedIn=true.
  2. getCustomerToken / getSellerToken are used by the Dio auth interceptor on every request.
  3. savePendingRegistrationData stashes phone/username/firstName/lastName between register and OTP verify.
  4. savePendingSellerOnboarding holds seller-type + selected services across the 'devenir prestataire' wizard.
  5. clearSession on logout removes tokens, role, profile-setup flag, ToS flag, and pending onboarding selections.

Cases & Edge Cases

  • FCM tracking key is keyed by (fcmToken, last 20 chars of authToken) so a token rotation forces a re-sync (see _getFcmTrackingKey).
  • clearSellerSession is callable independently — used when a user 'unbecomes' a seller without logging out.
  • Pending seller onboarding keys persist across app restarts; clearPendingSellerOnboarding must be called on completion to avoid stale carry-over.

Code References

  • lib/src/core/services/auth_storage.dart:9 // AuthStorageService
  • lib/src/core/services/auth_storage.dart:18 // saveCustomerSession
  • lib/src/core/services/auth_storage.dart:219 // _getFcmTrackingKey
  • lib/src/core/services/auth_storage.dart:242 // clearSession

API Calls

Empty — fill this in later. Open the manifest and add content here.

Notes

No secure storage — tokens live in SharedPreferences. Acceptable for Medusa session tokens (server-revocable) but means a rooted device can exfiltrate them. Local storage keys (no HTTP, SharedPreferences): • 'customer_token' — write: saveCustomerSession / saveSessionOtp — read: getCustomerToken (consumed by DioHelper auth interceptor) — clear: clearSession • 'seller_token' — write: saveSellerSession — read: getSellerToken — clear: clearSession + clearSellerSession • 'is_logged_in' — bool — read: isLoggedIn (consumed by GoRouter redirect + HomeScreen) • 'is_profile_setup_complete' — bool — write: markProfileSetupComplete (post-onboarding) • 'has_accepted_tos' — bool — write: markTosAccepted (after /store/tos/consent succeeds) • 'is_pending_seller_reg' — bool — write: setPendingSellerRegistration — gates the auth redirect to /onboarding_register_seller • 'pending_reg_{phone|username|first_name|last_name}' — String — write: savePendingRegistrationData (between register POST and OTP verify) — consumed by lib/src/features/shared/onboarding_register/presentation/pages/otp_step_page.dart • 'pending_seller_{type|services}' — write: savePendingSellerOnboarding — consumed by lib/src/features/client/devenir_prestataire/devenir_prestataire_screen.dart • 'fcm_sent_<fcmToken>_<authSuffix>' — bool — write/read: markFcmTokenSent / isFcmTokenSent — dedupes /fcm/token uploads