This is the code and i want that the user gets logged out as soon as he tries to enters another param in the url.
suppose his name is virat so the url will be http://localhost:3001/new/virat, but if he changes virat to rohit, i want him to get logged out.
How can i add this functionality using react?
Tried this code, but its not working.
const { username } = useParams();
const logoutR = async () => {
await fetch("http://localhost:3000/logout", {
method: "POST",
credentials: "include",
});
navigate("/login");
};
useEffect(() => {
let url = window.location.href;
if(!url.includes(username)){
logoutR()
}
}, [username])