File tree Expand file tree Collapse file tree
src/lib/features/auth/presentation/view Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import 'package:flutter/material.dart' ;
2+ import 'package:supabase_flutter/supabase_flutter.dart' ;
3+ import 'login_view.dart' ;
4+ import '../../../main/view/screens/main_screen.dart' ;
5+
6+ class AuthGate extends StatelessWidget {
7+ const AuthGate ({super .key});
8+
9+ @override
10+ Widget build (BuildContext context) {
11+ // StreamBuilder continously checks the auth state
12+ return StreamBuilder <AuthState >(
13+ stream: Supabase .instance.client.auth.onAuthStateChange,
14+ builder: (context, snapshot) {
15+ // Wait response from Supabase
16+ if (snapshot.connectionState == ConnectionState .waiting) {
17+ return const Scaffold (
18+ body: Center (child: CircularProgressIndicator ()),
19+ );
20+ }
21+
22+ // Check if there is an active session ( user logged in )
23+ final session = snapshot.data? .session;
24+
25+ // if session exists -> Navigate to MainScreen
26+ if (session != null ) {
27+ return const MainScreen ();
28+ }
29+
30+ // if session not exists -> Navigate to LoginView
31+ return const LoginView ();
32+ },
33+ );
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments