Die Push-Registrierung legt users/{uid} per merge selbst an (fcmTokens,
timezone) — beim kaputten Apple-Account existierte das Dokument daher
ohne householdId, und Gate + Bootstrap hielten den Account für fertig.
Jetzt prüfen beide auf householdId; der Bootstrap schreibt das
users-Dokument mit merge, damit die Push-Felder erhalten bleiben.
Neuer Test bildet exakt diesen Zustand ab.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
72 lines
2.7 KiB
Dart
72 lines
2.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../../core/firebase/firebase_providers.dart';
|
|
import '../../../l10n/generated/app_localizations.dart';
|
|
import '../data/household_bootstrap_provider.dart';
|
|
|
|
/// Hält die App zurück, solange zum angemeldeten Nutzer noch kein
|
|
/// users-Dokument (und damit kein Haushalt) existiert.
|
|
///
|
|
/// Beim ersten Login (z. B. mit Apple) legt [householdBootstrapProvider]
|
|
/// beides an; bis dahin gibt es einen Warte-Bildschirm. Schlägt der
|
|
/// Bootstrap fehl, wird der Fehler hier sichtbar — vorher konnte man in
|
|
/// der App landen, deren Schreibzugriffe dann alle an den Rules scheiterten.
|
|
class BootstrapGate extends ConsumerWidget {
|
|
const BootstrapGate({super.key, required this.child});
|
|
|
|
final Widget child;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final user = ref.watch(authStateProvider).value;
|
|
if (user == null) return child; // Login-Screen übernimmt.
|
|
|
|
final profile = ref.watch(userProfileProvider).value;
|
|
// householdId statt bloßer Dokument-Existenz: die Push-Registrierung
|
|
// legt das users-Dokument auch ohne Haushalt an.
|
|
final profileReady = profile != null &&
|
|
profile.id == user.uid &&
|
|
profile.data()?['householdId'] != null;
|
|
if (profileReady) return child;
|
|
|
|
final bootstrap = ref.watch(householdBootstrapProvider);
|
|
final l10n = AppLocalizations.of(context);
|
|
final theme = Theme.of(context);
|
|
return Scaffold(
|
|
body: SafeArea(
|
|
child: Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(24),
|
|
child: bootstrap.hasError
|
|
? Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(Icons.cloud_off,
|
|
size: 48, color: theme.colorScheme.error),
|
|
const SizedBox(height: 16),
|
|
Text(l10n.bootstrapFailed, textAlign: TextAlign.center),
|
|
const SizedBox(height: 16),
|
|
FilledButton(
|
|
onPressed: () => ref
|
|
.read(householdBootstrapProvider.notifier)
|
|
.retry(),
|
|
child: Text(l10n.bootstrapRetry),
|
|
),
|
|
],
|
|
)
|
|
: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const CircularProgressIndicator(),
|
|
const SizedBox(height: 16),
|
|
Text(l10n.bootstrapPreparing,
|
|
textAlign: TextAlign.center),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|