Future _checkUserLoginStatus() async { try { await Future.delayed(const Duration(seconds: 1)); log('Checking login status...'); final session = await _authRepo.fetchLocallyStored(); return session != null; } catch (e) { log('Error checking login status: $e'); return false; } } Future _redirectToLogin(String redirectPath) async { if (mounted) { GoRouter.of(context).push('/login?redirect=$redirectPath'); } } Future _handleDeepLink(BuildContext context) async { final GoRouterState state = GoRouterState.of(context); final String? deepLink = state.uri.toString().isNotEmpty && state.uri.path != '/' ? state.uri.toString() : null; if (deepLink == null) { log('No deep link detected.'); return; } log('Received deep link: $deepLink'); final String path = Uri.parse(deepLink).path; final bool isLoggedIn = await _checkUserLoginStatus(); if (!isLoggedIn) { log('User not logged in. Redirecting to login.'); await _redirectToLogin(path); return; } // If logged in, proceed to the shared page if (mounted) { log('User is logged in. Navigating to $path'); GoRouter.of(context).go(path); } } @override Widget build(BuildContext context) { return widget.child; } }