mirror of
https://github.com/Dvorinka/1356.git
synced 2026-06-04 20:12:56 +00:00
72 lines
2.4 KiB
Dart
72 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../application/auth_controller.dart';
|
|
import '../../onboarding/application/onboarding_controller.dart';
|
|
import '../../profile/application/profile_controller.dart';
|
|
import 'auth_showcase_screen.dart';
|
|
import '../../onboarding/presentation/onboarding_intro_screen.dart';
|
|
import '../../profile/presentation/profile_setup_screen.dart';
|
|
import '../../countdown/presentation/home_countdown_screen.dart';
|
|
import '../../../bootstrap/supabase_client.dart';
|
|
|
|
class AuthGate extends ConsumerStatefulWidget {
|
|
const AuthGate({super.key});
|
|
|
|
@override
|
|
ConsumerState<AuthGate> createState() => _AuthGateState();
|
|
}
|
|
|
|
class _AuthGateState extends ConsumerState<AuthGate> {
|
|
bool _isCheckingProfile = false;
|
|
bool _profileSetupComplete = false;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final authState = ref.watch(authControllerProvider);
|
|
final onboardingState = ref.watch(onboardingControllerProvider);
|
|
|
|
// If no backend is configured and there is no overridden auth state,
|
|
// keep the app usable by continuing through the local onboarding flow.
|
|
if (supabaseClient == null && authState == null) {
|
|
if (!onboardingState) {
|
|
return const OnboardingIntroScreen();
|
|
}
|
|
return const HomeCountdownScreen();
|
|
}
|
|
|
|
if (authState == null) {
|
|
return const AuthShowcaseScreen();
|
|
}
|
|
|
|
// If user is authenticated but hasn't completed onboarding
|
|
if (!onboardingState) {
|
|
return const OnboardingIntroScreen();
|
|
}
|
|
|
|
// Check if profile setup is complete
|
|
if (!_isCheckingProfile && !_profileSetupComplete) {
|
|
_isCheckingProfile = true;
|
|
_checkProfileSetup(authState.id);
|
|
return const Scaffold(body: Center(child: CircularProgressIndicator()));
|
|
}
|
|
|
|
// If profile setup is not complete, show profile setup screen
|
|
if (!_profileSetupComplete) {
|
|
return const ProfileSetupScreen();
|
|
}
|
|
|
|
// User is authenticated and has completed onboarding and profile setup
|
|
return const HomeCountdownScreen();
|
|
}
|
|
|
|
Future<void> _checkProfileSetup(String userId) async {
|
|
final isComplete = await ref.read(profileControllerProvider.notifier).isProfileSetupComplete(userId);
|
|
if (mounted) {
|
|
setState(() {
|
|
_profileSetupComplete = isComplete;
|
|
_isCheckingProfile = false;
|
|
});
|
|
}
|
|
}
|
|
}
|