arch-atlas

Home ToS / Pending-Seller Bootstrap

presentation/home.dart · _checkInitialTos / _checkPendingSeller

di

Overview

Post-frame side-effects fired the first time HomeScreen mounts: re-check ToS consent (in case the version bumped while logged in), and re-route to /devenir-prestataire if a pending-seller flag is set.

User Flow

  1. WidgetsBinding.instance.addPostFrameCallback schedules the work after the first build.
  2. authStateProvider.notifier.refreshAuthState() reloads (isLoggedIn, role) from storage.
  3. _checkInitialTos calls TosApiService.getLatestTos + checkConsent; if not consented, context.goNamed(termsOfService).
  4. _checkPendingSeller reads AuthStorageService.isPendingSellerRegistration; if true, context.goNamed(devenirPrestataire).

Cases & Edge Cases

  • Both checks early-return when isLoggedIn is false — guests don't touch /tos/latest at all.
  • If both ToS-stale and pending-seller fire, ToS wins (it's checked first and context.goNamed is async-fire-and-forget).
  • Errors are swallowed with a debugPrint — backend outage during ToS check leaves the user on /home rather than blocking them.

Code References

  • lib/src/features/shared/home/presentation/home.dart:34 // post-frame callback
  • lib/src/features/shared/home/presentation/home.dart:41 // _checkInitialTos
  • lib/src/features/shared/home/presentation/home.dart:63 // _checkPendingSeller
  • lib/src/features/shared/tos/data/tos_api_service.dart

API Calls

  • GET/store/tosno status

    Fetch the latest published ToS document (id, version, content URL).

    Response
    { id: string, version: string, contentUrl: string, ... } | null
    lib/src/features/shared/home/presentation/home.dart // _checkInitialTos + lib/src/features/shared/tos/presentation/terms_of_service_screen.dart

    auth: customer. Wrapped in TosApiService.

  • GET/store/tos/consent?termsVersion=:vno status

    Check whether the current user has consented to a given ToS version.

    Request
    Query: termsVersion=<string>
    Response
    200 (consented)
    Errors
    • ·404 — not yet consented
    lib/src/features/shared/home/presentation/home.dart + lib/src/core/routing/app_router.dart // _verifyTosConsent

    auth: customer. Result is memoized at module scope to avoid redirect spam.

  • POST/store/tos/consentno status

    Record the user's consent to a ToS version.

    Request
    { termsVersion: string }
    Response
    200 (no body)
    lib/src/features/shared/tos/presentation/terms_of_service_screen.dart // Accept button

    auth: customer.

Notes

Treat this as a redundant safety net — the GoRouter redirect is the primary gate. If you remove either check here, the redirect's memoization (_hasConsentedToS) must be invalidated on login.