add auth
This commit is contained in:
@@ -5,9 +5,11 @@
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'package:worker/features/account/presentation/pages/addresses_page.dart';
|
||||
import 'package:worker/features/auth/presentation/providers/auth_provider.dart';
|
||||
import 'package:worker/features/account/presentation/pages/change_password_page.dart';
|
||||
import 'package:worker/features/account/presentation/pages/profile_edit_page.dart';
|
||||
import 'package:worker/features/auth/domain/entities/business_unit.dart';
|
||||
@@ -39,20 +41,41 @@ import 'package:worker/features/showrooms/presentation/pages/design_request_crea
|
||||
import 'package:worker/features/showrooms/presentation/pages/design_request_detail_page.dart';
|
||||
import 'package:worker/features/showrooms/presentation/pages/model_houses_page.dart';
|
||||
|
||||
/// App Router
|
||||
/// Router Provider
|
||||
///
|
||||
/// Handles navigation throughout the app using declarative routing.
|
||||
/// Features:
|
||||
/// - Named routes for type-safe navigation
|
||||
/// - Authentication guards (TODO: implement when auth is ready)
|
||||
/// - Deep linking support
|
||||
/// - Transition animations
|
||||
class AppRouter {
|
||||
/// Router configuration
|
||||
static final GoRouter router = GoRouter(
|
||||
/// Provides GoRouter instance with auth state management
|
||||
final routerProvider = Provider<GoRouter>((ref) {
|
||||
final authState = ref.watch(authProvider);
|
||||
|
||||
return GoRouter(
|
||||
// Initial route
|
||||
initialLocation: RouteNames.login,
|
||||
|
||||
// Redirect based on auth state
|
||||
redirect: (context, state) {
|
||||
final isLoggedIn = authState.value != null;
|
||||
final isOnLoginPage = state.matchedLocation == RouteNames.login;
|
||||
final isOnRegisterPage = state.matchedLocation == RouteNames.register;
|
||||
final isOnBusinessUnitPage =
|
||||
state.matchedLocation == RouteNames.businessUnitSelection;
|
||||
final isOnOtpPage = state.matchedLocation == RouteNames.otpVerification;
|
||||
final isOnAuthPage =
|
||||
isOnLoginPage || isOnRegisterPage || isOnBusinessUnitPage || isOnOtpPage;
|
||||
|
||||
// If not logged in and not on auth pages, redirect to login
|
||||
if (!isLoggedIn && !isOnAuthPage) {
|
||||
return RouteNames.login;
|
||||
}
|
||||
|
||||
// If logged in and on login page, redirect to home
|
||||
if (isLoggedIn && isOnLoginPage) {
|
||||
return RouteNames.home;
|
||||
}
|
||||
|
||||
// No redirect needed
|
||||
return null;
|
||||
},
|
||||
|
||||
// Route definitions
|
||||
routes: [
|
||||
// Authentication Routes
|
||||
@@ -384,26 +407,10 @@ class AppRouter {
|
||||
),
|
||||
),
|
||||
|
||||
// Redirect logic for authentication (TODO: implement when auth is ready)
|
||||
// redirect: (context, state) {
|
||||
// final isLoggedIn = false; // TODO: Get from auth provider
|
||||
// final isOnLoginPage = state.matchedLocation == RouteNames.login;
|
||||
//
|
||||
// if (!isLoggedIn && !isOnLoginPage) {
|
||||
// return RouteNames.login;
|
||||
// }
|
||||
//
|
||||
// if (isLoggedIn && isOnLoginPage) {
|
||||
// return RouteNames.home;
|
||||
// }
|
||||
//
|
||||
// return null;
|
||||
// },
|
||||
|
||||
// Debug logging (disable in production)
|
||||
debugLogDiagnostics: true,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
/// Route Names
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user