feat: Add FAQ screen and navigation, implement authentication-gated access for home screen features, and dynamically render header menu options based on authentication status.
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:real_estate_mobile/features/auth/presentation/providers/auth_pro
|
||||
import 'package:real_estate_mobile/features/auth/presentation/screens/login_screen.dart';
|
||||
import 'package:real_estate_mobile/features/auth/presentation/screens/signup_screen.dart';
|
||||
import 'package:real_estate_mobile/features/agents/presentation/screens/agent_search_screen.dart';
|
||||
import 'package:real_estate_mobile/features/faq/presentation/screens/faq_screen.dart';
|
||||
import 'package:real_estate_mobile/features/home/presentation/screens/home_screen.dart';
|
||||
|
||||
final routerProvider = Provider<GoRouter>((ref) {
|
||||
@@ -18,25 +19,35 @@ final routerProvider = Provider<GoRouter>((ref) {
|
||||
authRefreshNotifier.dispose();
|
||||
});
|
||||
|
||||
// Public routes accessible without authentication (matching web middleware)
|
||||
const publicRoutes = ['/home', '/agents/search', '/faq'];
|
||||
const authRoutes = ['/login', '/signup'];
|
||||
|
||||
return GoRouter(
|
||||
initialLocation: '/login',
|
||||
initialLocation: '/home',
|
||||
refreshListenable: authRefreshNotifier,
|
||||
redirect: (context, state) {
|
||||
final authState = ref.read(authProvider);
|
||||
final isAuthenticated = authState.status == AuthStatus.authenticated;
|
||||
final isLoading = authState.status == AuthStatus.loading;
|
||||
|
||||
final isAuthRoute = state.matchedLocation == '/login' ||
|
||||
state.matchedLocation == '/signup';
|
||||
final location = state.matchedLocation;
|
||||
final isAuthRoute = authRoutes.contains(location);
|
||||
final isPublicRoute = publicRoutes.any(
|
||||
(route) => location == route || location.startsWith('$route/'),
|
||||
);
|
||||
|
||||
// While checking auth status, don't redirect
|
||||
if (isLoading) return null;
|
||||
|
||||
// If authenticated and on auth page, go to home
|
||||
// If authenticated and on auth page (login/signup), go to home
|
||||
if (isAuthenticated && isAuthRoute) return '/home';
|
||||
|
||||
// If not authenticated and on protected page, go to login
|
||||
if (!isAuthenticated && !isAuthRoute) return '/login';
|
||||
// Public routes are always accessible
|
||||
if (isPublicRoute || isAuthRoute) return null;
|
||||
|
||||
// Protected routes require authentication — redirect to login
|
||||
if (!isAuthenticated) return '/login';
|
||||
|
||||
return null;
|
||||
},
|
||||
@@ -60,6 +71,10 @@ final routerProvider = Provider<GoRouter>((ref) {
|
||||
return AgentSearchScreen(initialQuery: query);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '/faq',
|
||||
builder: (context, state) => const FaqScreen(),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user