I have created a login page using RTK query, and i have an Route of login and home page I have created a protected route based on the IsAuthenticated prop and wrapped protected route for home page and added a callback onLogin={handleLogin}
But the error says Login is not component
`Login.js
const [loginUser, { data, isLoading, isError }] = useLoginUserMutation();
useEffect(() => {
if (data?.response === "true" && data?.state === "success"){
setErrorMsg("");
setEmail("");
setPassword("");
setIsAuthenticated(true);
navigate("/home", { state: { user: data?.user } });
}
else if (data?.response === "false" && data.state === "error"){
setErrorMsg(true);
}
else{
setErrorMsg(false)
}
}, [data,isError,isLoading]);
const handleLogin = async (e) => {
e.preventDefault();
console.log("****")
await loginUser({email,password})
}
App.js
function App() {
const [isAuthenticated, setIsAuthenticated] = useState(false);
const handleLogin = () => {
setIsAuthenticated(true);
}
return (
<div className="App">
<Router>
<Routes>
<Route exact path="/">
<Login onLogin={handleLogin} />
</Route>
<ProtectedRoute path="/home" component={Home} isAuthenticated={isAuthenticated}/>
</Routes>
</Router>
</div>
);
}
export default App;
ProtectedRoute.js
import React from "react";
import { Route, Navigate } from "react-router-dom";
const ProtectedRoute = ({ isAuthenticated}) => {
return isAuthenticated? <Outlet /> : <Navigate to="/" />;
}
export default ProtectedRoute;`
I have tried adding the protectedRoute and unable to consume isAutheticated value from Login.js i used protected route to prevent back from login to home or vise versa