@@ -336,11 +336,15 @@ class AppBloc extends Bloc<AppEvent, AppState> {
336336 // If a new user is present, handle their data.
337337 if (newUser != null ) {
338338 // In demo mode, ensure essential user-specific data (settings,
339- // preferences, and the user object itself in the data client)
340- // are initialized if they don't already exist. This prevents
341- // NotFoundException during subsequent reads.
342- if (_environment == local_config.AppEnvironment .demo &&
343- demoDataInitializerService != null ) {
339+ // preferences) are initialized if they don't already exist.
340+ final isDemoMode = _environment == local_config.AppEnvironment .demo;
341+ final isMigration =
342+ oldUser != null &&
343+ oldUser.appRole == AppUserRole .guestUser &&
344+ newUser.appRole == AppUserRole .standardUser;
345+
346+ // Initialize data for a new user, but ONLY if it's not a migration.
347+ if (isDemoMode && ! isMigration && demoDataInitializerService != null ) {
344348 _logger.info (
345349 '[AppBloc] Demo mode: Initializing user-specific data for '
346350 'user: ${newUser .id }' ,
@@ -376,9 +380,7 @@ class AppBloc extends Bloc<AppEvent, AppState> {
376380 }
377381
378382 // Handle data migration if an anonymous user signs in.
379- if (oldUser != null &&
380- oldUser.appRole == AppUserRole .guestUser &&
381- newUser.appRole == AppUserRole .standardUser) {
383+ if (isMigration) {
382384 _logger.info (
383385 '[AppBloc] Anonymous user ${oldUser .id } transitioned to '
384386 'authenticated user ${newUser .id }. Attempting data migration.' ,
@@ -414,10 +416,11 @@ class AppBloc extends Bloc<AppEvent, AppState> {
414416 }
415417 }
416418
417- // If not in demo mode, or if the demo initializer is not used,
418- // perform the standard data fetch. In demo mode, this call is now
419- // redundant as it's handled immediately after initialization.
420- if (_environment != local_config.AppEnvironment .demo) {
419+ // Perform the standard data fetch if we are not in demo mode, or if a
420+ // migration just occurred (to load the migrated data).
421+ // This avoids a redundant fetch in the demo initialization path, which
422+ // handles its own data fetching after creating fixture data.
423+ if (! isDemoMode || isMigration) {
421424 await _fetchAndSetUserData (newUser, emit);
422425 }
423426 } else {
0 commit comments