import 'dart:async';

import 'package:astronp/features/chat/presentation/pages/chat_page.dart';
import 'package:astronp/features/discover/presentation/pages/aggregate_matching_page.dart';
import 'package:astronp/features/discover/presentation/pages/daily_prediction_page.dart';
import 'package:astronp/features/discover/presentation/pages/discover_page.dart';
import 'package:astronp/features/discover/presentation/pages/personal_characteristics_page.dart';
import 'package:astronp/features/discover/presentation/pages/information_page.dart';
import 'package:astronp/features/discover/presentation/pages/weekly_prediction_page.dart';
import 'package:astronp/features/discover/presentation/pages/yearly_prediction_page.dart';
import 'package:astronp/features/home_page/models/blog.dart';
import 'package:astronp/features/home_page/presentation/pages/blog_page.dart';
import 'package:astronp/features/home_page/presentation/pages/read_blog_page.dart';
import 'package:astronp/features/profile/pages/edit_profile_page.dart';
import 'package:astronp/features/discover/presentation/pages/gem_suggestion_page.dart';
import 'package:astronp/features/discover/presentation/pages/western_matching_page.dart';
import 'package:astronp/features/profile/pages/profile_page.dart';
import 'package:astronp/main.dart';
import 'package:astronp/shared/features/login/login_page.dart';
import 'package:astronp/shared/features/paywall/store_page.dart';
import 'package:astronp/shared/features/login/user_info_page.dart';
import 'package:astronp/shared/features/login/error_page.dart';
import 'package:auto_route/auto_route.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';

part 'app_router.gr.dart';

/// Manages all [routing logic] for the application.
/// Allows defining `routes` and specifying `initial routes`.
/// [Guards] can also be added here to control access to routes.

@AutoRouterConfig()
class AppRouter extends _$AppRouter {
  /// Specifies the `default` [route type] for the application.
  /// Here, we use a `custom route` type with [no transition duration].
  // @override
  // RouteType get defaultRouteType =>
  //     const RouteType.custom(durationInMilliseconds: 0);

  /// Defines the `list of routes` for the application.
  @override
  List<AutoRoute> get routes => [
        AutoRoute(
          page: MyHomeRoute.page,
          initial: true,
          guards: [AuthGuard(), UserDataGuard()],
        ),
        AutoRoute(
          page: ChatRoute.page,
          guards: [AuthGuard(), UserDataGuard()],
        ),
        AutoRoute(
          page: DiscoverRoute.page,
          // initial: true,
          guards: [AuthGuard(), UserDataGuard()],
        ),
        AutoRoute(
          page: DailyPredictionRoute.page,
          guards: [AuthGuard(), UserDataGuard()],
        ),
        AutoRoute(
          page: WeeklyPredictionRoute.page,
          guards: [AuthGuard(), UserDataGuard()],
        ),
        AutoRoute(
          page: YearlyPredictionRoute.page,
          guards: [AuthGuard(), UserDataGuard()],
        ),
        AutoRoute(
          page: BlogRoute.page,
          guards: [AuthGuard(), UserDataGuard()],
        ),
        AutoRoute(
          page: ReadBlogRoute.page,
          guards: [AuthGuard(), UserDataGuard()],
        ),
        AutoRoute(
          page: ProfileRoute.page,
          // initial: true,
          guards: [AuthGuard(), UserDataGuard()],
        ),
        AutoRoute(
          page: EditProfileRoute.page,
          guards: [AuthGuard(), UserDataGuard()],
        ),
        AutoRoute(
          page: GemSuggestionRoute.page,
          guards: [AuthGuard(), UserDataGuard()],
        ),
        AutoRoute(
          page: AggregateMatchingRoute.page,
          guards: [AuthGuard(), UserDataGuard()],
        ),
        AutoRoute(
          page: PersonalCharacteristicsRoute.page,
          guards: [AuthGuard(), UserDataGuard()],
        ),
        AutoRoute(
          page: WesternMatchingRoute.page,
          guards: [AuthGuard(), UserDataGuard()],
        ),
        AutoRoute(
          page: StoreRoute.page,
          // initial: true,
          guards: [AuthGuard(), UserDataGuard()],
        ),
        AutoRoute(
          page: InformationRoute.page,
          guards: [AuthGuard(), UserDataGuard()],
        ),
        AutoRoute(
          page: LoginRoute.page,
        ),
        AutoRoute(
          page: UserInfoRoute.page,
          guards: [AuthGuard()],
        ),
      ];
}

class AuthGuard extends AutoRouteGuard {
  final FirebaseAuth _auth = FirebaseAuth.instance;

  @override
  void onNavigation(NavigationResolver resolver, StackRouter router) {
    var userStream = _auth.authStateChanges();
    late StreamSubscription<User?> subscription;

    subscription = userStream.listen((User? user) async {
      if (user != null) {
        resolver.next(true);
      } else {
        router.pushAndPopUntil(
          const LoginRoute(),
          predicate: (route) => false,
        );
      }
      subscription.cancel();
    }, onError: (error) {
      print("Error checking user authentication: $error");
      router.push(ErrorRoute());
    });
  }
}


class UserDataGuard extends AutoRouteGuard {
  final FirebaseAuth _auth = FirebaseAuth.instance;
  final FirebaseFirestore _firestore = FirebaseFirestore.instance;

  @override
  void onNavigation(NavigationResolver resolver, StackRouter router) async {
    User? user = _auth.currentUser;

    if (user != null) {
      final docSnapshot =
          await _firestore.collection('users').doc(user.uid).get();

      print(user.uid);
      if (docSnapshot.exists) {
        print(
            "UserDataGuard: User data exists in Firestore. Proceeding to next route.");
        resolver.next(true);
      } else {
        print(
            "UserDataGuard: User data doesn't exist in Firestore. Redirecting to UserInfoRoute.");
        router.push(const UserInfoRoute());
      }
    } else {
      print(
          "UserDataGuard: User is not authenticated. This shouldn't happen if AuthenticationGuard is used first.");
      router.push(const LoginRoute());
    }
  }
}



So that is the routing using auto route Lucy, this is flutter but I am sure you already know that.

So, basically we have an issue. 
When the user logins, we send the user to the homepage, fair enough, however.
When the user signs up, of course if there is no user data, then it would send the user to the user info page, where the user can enter the info, however, there's an issue.

When the user signs up instead of it going to the user info page, it goes to the login page again, and then I have to login again and then it goes to the user info page, which is not what I want. Can you fix the code for me please to do what I want it to do?

Nope, still the same issue.
Here is the login page code just in case you want to check it.

class LoginPage extends StatefulHookConsumerWidget {
  const LoginPage({super.key});

  @override
  ConsumerState<ConsumerStatefulWidget> createState() => _LoginPageState();
}

class _LoginPageState extends ConsumerState<LoginPage> {
  @override
  Widget build(BuildContext context) {
    final dio = ref.watch(dioProvider);
    final isLogin = useState(true);
    final email = useState('');
    final password = useState('');

    void handleSocialLogin(String provider) {
      print('Logging in with $provider');
    }

    final loginRepo = ref.read(loginRepositoryProvider);

    return Scaffold(
      body: Container(
        decoration: const BoxDecoration(
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors: [Color(0xFFE6F0FF), Color(0xFFF0E6FF)],
          ),
        ),
        child: SafeArea(
          child: Center(
            child: SingleChildScrollView(
              padding: const EdgeInsets.all(16),
              child: Padding(
                padding: const EdgeInsets.all(30.0),
                child: Container(
                  width: 400,
                  padding: const EdgeInsets.all(24),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(12),
                    boxShadow: [
                      BoxShadow(
                        color: Colors.black.withOpacity(0.1),
                        blurRadius: 10,
                        offset: const Offset(0, 5),
                      ),
                    ],
                  ),
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Image.asset(
                        'assets/images/astronp_logo.png',
                        height: 140,
                      ),
                      Text(
                        isLogin.value
                            ? 'Log in to Astro NP'
                            : 'Sign up for Astro NP',
                        style: TextStyle(
                          fontSize: 24,
                          fontWeight: FontWeight.bold,
                          color: Colors.grey[800],
                        ),
                      ),
                      const SizedBox(height: 24),
                      TextField(
                        onChanged: (value) => email.value = value,
                        decoration: InputDecoration(
                          hintText: 'Email address',
                          prefixIcon:
                              const Icon(Icons.email, color: Colors.grey),
                          filled: true,
                          fillColor: Colors.grey[50],
                          border: OutlineInputBorder(
                            borderRadius: BorderRadius.circular(8),
                            borderSide: BorderSide.none,
                          ),
                        ),
                      ),
                      const SizedBox(height: 16),
                      TextField(
                        onChanged: (value) => password.value = value,
                        obscureText: true,
                        decoration: InputDecoration(
                          hintText: 'Password',
                          prefixIcon:
                              const Icon(Icons.lock, color: Colors.grey),
                          filled: true,
                          fillColor: Colors.grey[50],
                          border: OutlineInputBorder(
                            borderRadius: BorderRadius.circular(8),
                            borderSide: BorderSide.none,
                          ),
                        ),
                      ),
                      const SizedBox(height: 24),
                      StatefulButton(
                        onPressed: () async {
                          if (email.value.isEmpty || password.value.isEmpty) {
                            showCustomSnackBar(
                                context, 'Please fill in all fields');
                            return false;
                          } else {
                            if (isLogin.value) {
                              final result = await loginRepo.login(
                                  email.value, password.value);
                              if (result && context.mounted) {
                                context.router.pushAndPopUntil(
                                  const MyHomeRoute(),
                                  predicate: (_) => false,
                                );
                              } else {
                                if (context.mounted) {
                                  showCustomSnackBar(
                                      context, 'Invalid email or password');
                                }
                              }
                              return result;
                            } else {
                              final result = await loginRepo.register(
                                  email.value, password.value);
                              if (result && context.mounted) {
                                context.router.push(const UserInfoRoute());
                              } else {
                                if (context.mounted) {
                                  showCustomSnackBar(
                                      context, 'Registration failed');
                                }
                              }
                              return result;
                            }
                          }
                        },
                        label: isLogin.value ? 'Log in' : 'Sign up',
                      ),
                      const SizedBox(height: 16),
                      TextButton(
                        onPressed: () => isLogin.value = !isLogin.value,
                        child: Text(
                          isLogin.value
                              ? 'Need an account? Sign up'
                              : 'Already have an account? Log in',
                          style: TextStyle(color: Colors.indigo[600]),
                        ),
                      ),
                      const SizedBox(height: 24),
                      TextButton(
                        onPressed: () =>
                            showPasswordResetBottomSheet(context, loginRepo),
                        child: Text(
                          'Forgot password?',
                          style: TextStyle(color: Colors.grey[600]),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

Not sure what's going on, no matter what I do it's not working.