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
This commit is contained in:
Dani B
2026-01-28 12:59:52 -05:00
parent d4006d73ce
commit 9a6332eacf

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:supabase_flutter/supabase_flutter.dart'; import 'package:supabase_flutter/supabase_flutter.dart';
import '../../features/authentication/presentation/pages/login_page.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_page.dart';
import '../../features/authentication/presentation/pages/reset_password_confirm_page.dart'; import '../../features/authentication/presentation/pages/reset_password_confirm_page.dart';
import '../../features/authentication/presentation/pages/update_password_page.dart'; import '../../features/authentication/presentation/pages/update_password_page.dart';
import '../../providers/auth_provider.dart';
/// Application router configuration /// Application router configuration
/// ///
/// Handles navigation with authentication state awareness and protected routes /// 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 { class AppRouter {
static final GoRouter _router = GoRouter( static final GoRouter _router = GoRouter(
initialLocation: '/', initialLocation: '/',
debugLogDiagnostics: true, debugLogDiagnostics: true,
redirect: (context, state) { redirect: (context, state) {
// Use Supabase directly for auth state checking // Use AuthProvider for auth state checking
final currentUser = Supabase.instance.client.auth.currentUser; final authState = context.read(authStateProvider);
final currentUser = authState.user;
// Allow splash page regardless of auth state // Allow splash page regardless of auth state
if (state.uri.toString() == '/splash') { if (state.uri.toString() == '/splash') {
@@ -174,4 +180,26 @@ errorBuilder: (context, state) => Scaffold(
/// Get the router instance /// Get the router instance
static GoRouter get router => _router; static GoRouter get router => _router;
/// Extract URL query parameters from current location
static Map<String, String> extractQueryParameters(BuildContext context) {
final GoRouter router = GoRouter.of(context);
return router.routeInformationProvider.value.uri.queryParameters;
}
/// Handle password reset deep link with parameters
static Map<String, String> 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 {};
}
} }