From 9a6332eacf2d0b870c388775813653eac618ca95 Mon Sep 17 00:00:00 2001 From: Dani B Date: Wed, 28 Jan 2026 12:59:52 -0500 Subject: [PATCH] fix(01-10): update router to use AuthProvider - Updated AppRouter to use AuthProvider instead of direct Supabase calls - Ensures proper navigation after logout through state management - Router now correctly responds to AuthProvider state changes --- lib/core/router/app_router.dart | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/core/router/app_router.dart b/lib/core/router/app_router.dart index 1f99b8d..d09b669 100644 --- a/lib/core/router/app_router.dart +++ b/lib/core/router/app_router.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:supabase_flutter/supabase_flutter.dart'; import '../../features/authentication/presentation/pages/login_page.dart'; @@ -9,17 +10,22 @@ 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'; +import '../../providers/auth_provider.dart'; /// Application router configuration /// /// Handles navigation with authentication state awareness and protected routes +/// Supports deep linking for password reset URLs +/// URL scheme for mobile: sage://reset-password?token=xxx&email=xxx +/// Web URLs: https://app.sage.com/reset-password?token=xxx&email=xxx class AppRouter { static final GoRouter _router = GoRouter( initialLocation: '/', debugLogDiagnostics: true, redirect: (context, state) { - // Use Supabase directly for auth state checking - final currentUser = Supabase.instance.client.auth.currentUser; + // Use AuthProvider for auth state checking + final authState = context.read(authStateProvider); + final currentUser = authState.user; // Allow splash page regardless of auth state if (state.uri.toString() == '/splash') { @@ -174,4 +180,26 @@ errorBuilder: (context, state) => Scaffold( /// Get the router instance static GoRouter get router => _router; + + /// Extract URL query parameters from current location + static Map extractQueryParameters(BuildContext context) { + final GoRouter router = GoRouter.of(context); + return router.routeInformationProvider.value.uri.queryParameters; + } + + /// Handle password reset deep link with parameters + static Map handlePasswordResetDeepLink(BuildContext context) { + final params = extractQueryParameters(context); + final token = params['token']; + final email = params['email']; + + if (token != null && email != null) { + // Store secure data for password reset flow + // TODO: Implement secure storage mechanism + print('Password reset deep link received for: $email'); + return {'token': token, 'email': email}; + } + + return {}; + } } \ No newline at end of file