I'm pretty new to React. I'm trying to create a private route handler with the new release of react-router-dom v6, so I need to verify whether the user is authenticated or not in order to know if return the protected route or redirect the user to the login route.
import { Navigate } from 'react-router-dom';
import { useSelector } from 'react-redux';
import { isLogged } from '../helpers/isLogged';
export const PrivateRoute = async ({children}) => {
// Check if the user is authenticated
const userData = useSelector( store => store.user.object);
const logged = await isLogged(userData);
return logged
? children
: <Navigate to="/login" />;
}
The thing is i'm getting some errors due to this, but mainly the object promise one.
What's going on? Thanks in advance!