0661016827
- Replace Email+Password login with Phone+OTP flow - Remove RegisterCubit and registration screens (email verification) - Remove ResetPasswordCubit and reset password screens - Add phone normalization and international dial code support - Update LoginCubit with sendCode/resend cooldown logic - Add new widgets: phone prefix selector, confirm sheet - Update all auth API endpoints: /otp/send, /phone-session - Update form inputs: Email -> Phone with E.164 validation - Update tests for new auth flow
188 lines
6.7 KiB
Dart
188 lines
6.7 KiB
Dart
import 'package:go_router/go_router.dart';
|
|
import 'app_route_observer.dart';
|
|
import '../../features/auth/presentation/bloc/auth_bloc.dart';
|
|
import '../../features/auth/presentation/bloc/auth_state.dart';
|
|
import 'app_routes.dart';
|
|
import 'go_router_refresh_stream.dart';
|
|
import '../../features/auth/ui/screens/auth_boot_screen.dart';
|
|
import '../../features/auth/ui/screens/login_screen.dart';
|
|
import '../../features/home/ui/screens/home_screen.dart';
|
|
import '../../features/messages/ui/screens/message_invite_list_screen.dart';
|
|
import '../../features/messages/ui/screens/message_invite_detail_screen.dart';
|
|
import '../../features/contacts/ui/screens/contacts_screen.dart';
|
|
import '../../features/contacts/ui/screens/add_contact_screen.dart';
|
|
import '../../features/calendar/ui/screens/calendar_dayweek_screen.dart';
|
|
import '../../features/calendar/ui/screens/calendar_month_screen.dart';
|
|
import '../../features/calendar/ui/screens/calendar_event_detail_screen.dart';
|
|
import '../../features/calendar/ui/screens/calendar_event_create_screen.dart';
|
|
import '../../features/calendar/ui/screens/calendar_event_edit_screen.dart';
|
|
import '../../features/calendar/ui/screens/calendar_event_share_screen.dart';
|
|
import '../../features/calendar/ui/calendar_time_utils.dart';
|
|
import '../../features/todo/ui/screens/todo_quadrants_screen.dart';
|
|
import '../../features/todo/ui/screens/todo_detail_screen.dart';
|
|
import '../../features/todo/ui/screens/todo_edit_screen.dart';
|
|
import '../../features/settings/ui/screens/settings_screen.dart';
|
|
import '../../features/settings/ui/screens/features_screen.dart';
|
|
import '../../features/settings/ui/screens/memory_screen.dart';
|
|
import '../../features/settings/ui/screens/account_screen.dart';
|
|
import '../../features/settings/ui/screens/edit_profile_screen.dart';
|
|
|
|
final _protectedRoutes = [
|
|
AppRoutes.homeMain,
|
|
AppRoutes.contactsList,
|
|
AppRoutes.contactsAdd,
|
|
AppRoutes.calendarDayWeek,
|
|
AppRoutes.calendarMonth,
|
|
'/calendar/events',
|
|
AppRoutes.todoList,
|
|
AppRoutes.settingsMain,
|
|
AppRoutes.settingsFeatures,
|
|
AppRoutes.settingsMemory,
|
|
AppRoutes.settingsAccount,
|
|
AppRoutes.settingsEditProfile,
|
|
AppRoutes.messageInviteList,
|
|
];
|
|
|
|
GoRouter createAppRouter(AuthBloc authBloc) {
|
|
return GoRouter(
|
|
initialLocation: AppRoutes.authBoot,
|
|
observers: [appRouteObserver],
|
|
refreshListenable: GoRouterRefreshStream(authBloc.stream),
|
|
redirect: (context, state) {
|
|
final authState = authBloc.state;
|
|
final isAuthenticated = authState is AuthAuthenticated;
|
|
final isAuthChecking =
|
|
authState is AuthInitial || authState is AuthLoading;
|
|
final isBootRoute = state.matchedLocation == AppRoutes.authBoot;
|
|
final isAuthRoute =
|
|
state.matchedLocation == AppRoutes.authLogin ||
|
|
state.matchedLocation.startsWith('/login');
|
|
final isProtected = _protectedRoutes.any(
|
|
(route) => state.matchedLocation.startsWith(route),
|
|
);
|
|
|
|
if (isAuthChecking && !isBootRoute) {
|
|
return AppRoutes.authBoot;
|
|
}
|
|
if (!isAuthChecking && isBootRoute) {
|
|
return isAuthenticated ? AppRoutes.homeMain : AppRoutes.authLogin;
|
|
}
|
|
if (!isAuthenticated && isProtected) {
|
|
return AppRoutes.authLogin;
|
|
}
|
|
if (isAuthenticated && isAuthRoute) {
|
|
return AppRoutes.homeMain;
|
|
}
|
|
return null;
|
|
},
|
|
routes: [
|
|
GoRoute(
|
|
path: AppRoutes.authBoot,
|
|
builder: (context, state) => const AuthBootScreen(),
|
|
),
|
|
GoRoute(
|
|
path: AppRoutes.calendarEventCreate,
|
|
builder: (context, state) => CalendarEventCreateScreen(
|
|
initialDate: parseYmd(state.uri.queryParameters['date']),
|
|
),
|
|
),
|
|
GoRoute(
|
|
path: '/calendar/events/:id',
|
|
builder: (context, state) =>
|
|
CalendarEventDetailScreen(eventId: state.pathParameters['id']!),
|
|
),
|
|
GoRoute(
|
|
path: '/calendar/events/:id/edit',
|
|
builder: (context, state) =>
|
|
CalendarEventEditScreen(eventId: state.pathParameters['id']!),
|
|
),
|
|
GoRoute(
|
|
path: '/calendar/events/:id/share',
|
|
builder: (context, state) =>
|
|
CalendarEventShareScreen(eventId: state.pathParameters['id']!),
|
|
),
|
|
GoRoute(
|
|
path: AppRoutes.authLogin,
|
|
builder: (context, state) => const LoginScreen(),
|
|
),
|
|
GoRoute(
|
|
path: AppRoutes.homeMain,
|
|
builder: (context, state) => const HomeScreen(),
|
|
),
|
|
GoRoute(
|
|
path: AppRoutes.messageInviteList,
|
|
builder: (context, state) => const MessageInviteListScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/messages/invites/:id',
|
|
builder: (context, state) =>
|
|
MessageInviteDetailScreen(inviteId: state.pathParameters['id']!),
|
|
),
|
|
GoRoute(
|
|
path: AppRoutes.contactsList,
|
|
builder: (context, state) => const ContactsScreen(),
|
|
),
|
|
GoRoute(
|
|
path: AppRoutes.contactsAdd,
|
|
builder: (context, state) => const AddContactScreen(),
|
|
),
|
|
GoRoute(
|
|
path: AppRoutes.calendarDayWeek,
|
|
builder: (context, state) {
|
|
final fromHome = state.uri.queryParameters['from'] == 'home';
|
|
final initialDate = parseYmd(state.uri.queryParameters['date']);
|
|
return CalendarDayWeekScreen(
|
|
initialDate: initialDate,
|
|
resetToToday: fromHome,
|
|
);
|
|
},
|
|
),
|
|
GoRoute(
|
|
path: AppRoutes.calendarMonth,
|
|
builder: (context, state) {
|
|
final fromHome = state.uri.queryParameters['from'] == 'home';
|
|
return CalendarMonthScreen(resetToToday: fromHome);
|
|
},
|
|
),
|
|
GoRoute(
|
|
path: AppRoutes.todoList,
|
|
builder: (context, state) => const TodoQuadrantsScreen(),
|
|
),
|
|
GoRoute(
|
|
path: AppRoutes.todoCreate,
|
|
builder: (context, state) => const TodoEditScreen.create(),
|
|
),
|
|
GoRoute(
|
|
path: '/todo/:id',
|
|
builder: (context, state) =>
|
|
TodoDetailScreen(todoId: state.pathParameters['id']!),
|
|
),
|
|
GoRoute(
|
|
path: '/todo/:id/edit',
|
|
builder: (context, state) =>
|
|
TodoEditScreen(todoId: state.pathParameters['id']!),
|
|
),
|
|
GoRoute(
|
|
path: AppRoutes.settingsMain,
|
|
builder: (context, state) => const SettingsScreen(),
|
|
),
|
|
GoRoute(
|
|
path: AppRoutes.settingsFeatures,
|
|
builder: (context, state) => const FeaturesScreen(),
|
|
),
|
|
GoRoute(
|
|
path: AppRoutes.settingsMemory,
|
|
builder: (context, state) => const MemoryScreen(),
|
|
),
|
|
GoRoute(
|
|
path: AppRoutes.settingsAccount,
|
|
builder: (context, state) => const AccountScreen(),
|
|
),
|
|
GoRoute(
|
|
path: AppRoutes.settingsEditProfile,
|
|
builder: (context, state) => const EditProfileScreen(),
|
|
),
|
|
],
|
|
);
|
|
}
|