37 lines
970 B
Dart
37 lines
970 B
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../providers/auth_provider.dart';
|
|
import '../pages/login_page.dart';
|
|
|
|
/// Wrapper widget that checks authentication status
|
|
/// Shows login page if not authenticated, otherwise shows child widget
|
|
class AuthWrapper extends ConsumerWidget {
|
|
const AuthWrapper({
|
|
super.key,
|
|
required this.child,
|
|
});
|
|
|
|
final Widget child;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final authState = ref.watch(authProvider);
|
|
|
|
// Show loading indicator while checking auth status
|
|
if (authState.isLoading && authState.user == null) {
|
|
return const Scaffold(
|
|
body: Center(
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
);
|
|
}
|
|
|
|
// Show child widget if authenticated, otherwise show login page
|
|
if (authState.isAuthenticated) {
|
|
return child;
|
|
} else {
|
|
return const LoginPage();
|
|
}
|
|
}
|
|
}
|