diff --git a/lib/core/router/app_router.dart b/lib/core/router/app_router.dart index 4543fb5..1f99b8d 100644 --- a/lib/core/router/app_router.dart +++ b/lib/core/router/app_router.dart @@ -6,6 +6,9 @@ import '../../features/authentication/presentation/pages/login_page.dart'; import '../../features/authentication/presentation/pages/signup_page.dart'; import '../../features/home/presentation/pages/home_page.dart'; import '../../features/authentication/presentation/pages/splash_page.dart'; +import '../../features/authentication/presentation/pages/reset_password_page.dart'; +import '../../features/authentication/presentation/pages/reset_password_confirm_page.dart'; +import '../../features/authentication/presentation/pages/update_password_page.dart'; /// Application router configuration /// @@ -24,12 +27,20 @@ class AppRouter { } // If not authenticated and trying to access protected route, redirect to login - if (currentUser == null && !state.uri.toString().startsWith('/login') && !state.uri.toString().startsWith('/signup')) { + // Allow password reset routes regardless of auth state for deep linking + if (currentUser == null && + !state.uri.toString().startsWith('/login') && + !state.uri.toString().startsWith('/signup') && + !state.uri.toString().startsWith('/reset-password') && + !state.uri.toString().startsWith('/update-password')) { return '/login'; } - // If authenticated and on auth pages, redirect to home - if (currentUser != null && (state.uri.toString().startsWith('/login') || state.uri.toString().startsWith('/signup'))) { + // If authenticated and on auth pages (except password reset), redirect to home + if (currentUser != null && + (state.uri.toString().startsWith('/login') || + state.uri.toString().startsWith('/signup') || + state.uri.toString().startsWith('/reset-password'))) { return '/home'; } @@ -53,6 +64,47 @@ class AppRouter { builder: (context, state) => const SignupPage(), ), + // Password reset routes (public for deep linking) + GoRoute( + path: '/reset-password', + builder: (context, state) => const ResetPasswordPage(), + ), + + GoRoute( + path: '/reset-password-confirm', + builder: (context, state) { + // Extract token from query parameters for deep linking + final token = state.uri.queryParameters['token']; + final email = state.uri.queryParameters['email']; + + // Store token data for password reset flow + if (token != null && email != null) { + // TODO: Store token and email securely for password reset flow + // This could be done through a provider or secure storage + print('Password reset token received for email: $email'); + } + + return const ResetPasswordConfirmPage(); + }, + ), + + GoRoute( + path: '/update-password', + builder: (context, state) { + // Extract token from query parameters if present + final token = state.uri.queryParameters['token']; + final email = state.uri.queryParameters['email']; + + // Store token data for password update + if (token != null && email != null) { + // TODO: Store token and email securely for password update flow + print('Password update token received for email: $email'); + } + + return const UpdatePasswordPage(); + }, + ), + // Protected routes (require authentication) GoRoute( path: '/home', @@ -106,6 +158,14 @@ errorBuilder: (context, state) => Scaffold( }, child: const Text('Go Home'), ), + const SizedBox(height: 16), + // Special handling for malformed password reset URLs + if (state.uri.toString().contains('reset')) ...[ + TextButton( + onPressed: () => GoRouter.of(context).go('/reset-password'), + child: const Text('Request New Reset Link'), + ), + ], ], ), ),