How do I check whether a user is logged in and based on the auth state how do we navigate to different pages, in React Native with AWS Amplify Auth

I am creating an app with react native and using AWS amplify authentication. I want to create an authentication flow. I am following the docs to implement sign in, sign up, and sign out. These all are working fine. But the problem is I don’t know how to navigate based on the authentication state. Currently, when a log in is succesful, I want to navigate to the home screen, but I get the error that ‘The action ‘NAVIGATE’ was not handled by any navigator.’ But if i reload the app, then the app opens on the home screen. So I know that the user has been signed in correctly and the problem is something with navigation. I am using amplify V6.

This is the App.js

import "react-native-get-random-values";
import { useEffect, useState } from "react";
import { Amplify } from "aws-amplify";
import awsconfig from "./aws-exports";
import { getCurrentUser } from "aws-amplify/auth";
import { StatusBar } from "expo-status-bar";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import theme from "./theme";
import LandingScreen from "./screens/Auth/LandingScreen";
import LoginScreen from "./screens/Auth/LoginScreen";
import CreateAccountScreen from "./screens/Auth/CreateAccountScreen";
import HomeScreen from "./screens/HomeScreen";

Amplify.configure(awsconfig);

const Stack = createNativeStackNavigator();

export default function App() {
    const [isAuthenticated, setIsAuthenticated] = useState(null);
    useEffect(() => {
        async function checkUser() {
            try {
                const user = await getCurrentUser();
                if (user) {
                    setIsAuthenticated(true);
                } else {
                    setIsAuthenticated(false);
                }
            } catch (err) {
                console.log(err);
                setIsAuthenticated(false);
            }
        }
        checkUser();
    }, []);


    return (
        <NavigationContainer>
            <StatusBar style="dark" />
            <Stack.Navigator
                screenOptions={{
                    headerShown: false,
                }}>
                {isAuthenticated ? (
                    <Stack.Screen name="HomeScreen" component={HomeScreen} />
                ) : (
                    <>
                        <Stack.Screen
                            name="LandingScreen"
                            component={LandingScreen}
                        />
                    </>
                )}
                <Stack.Screen name="LoginScreen" component={LoginScreen} />
                <Stack.Screen
                    name="CreateAccountScreen"
                    component={CreateAccountScreen}
                />
            </Stack.Navigator>
        </NavigationContainer>
    );
}

This is the login screen:

import React, { useState } from "react";
import { View, Text, TextInput, Button, StyleSheet, Alert } from "react-native";
import { signIn } from "@aws-amplify/auth";
import { useNavigation } from "@react-navigation/native";
import theme from "../../theme";

export default function LoginScreen() {
    const [username, setUsername] = useState("");
    const [password, setPassword] = useState("");
    const navigation = useNavigation();

    const handleSignIn = async () => {
        try {
            const { isSignedIn, nextStep } = await signIn({
                username,
                password,
            });
            if (isSignedIn) {
                Alert.alert("Sign in successful!");
                navigation.navigate("HomeScreen");
            } else {
                Alert.alert("Sign in not completed:", nextStep);
            }
        } catch (error) {
            Alert.alert("Error signing in:", error.message);
        }
    };

    return (
        <View>
            <TextInput
                placeholder="Username"
                value={username}
                onChangeText={setUsername}
            />
            <TextInput
                placeholder="Password"
                secureTextEntry
                value={password}
                onChangeText={setPassword}
            />
            <Button title="Sign In" onPress={handleSignIn} />
        </View>
    );
}

These are the relevant dependency versions:
“aws-amplify”: “^6.3.3”,
“@aws-amplify/react-native”: “^1.1.1”,
“@aws-amplify/auth”: “^6.3.3”

I want to find a way to navigate the user to the correct page based on whether they are signed in or not. I have not used AWS before so I am not sure what to do.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật