#20 Made logout page
This commit is contained in:
24
frontend/src/pages/LogoutPage.jsx
Normal file
24
frontend/src/pages/LogoutPage.jsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { useContext, useEffect } from "react";
|
||||
import UserContext from "../contexts/UserContext";
|
||||
import { makeRequest } from "../utils.ts";
|
||||
|
||||
const LogoutPage = () => {
|
||||
const { setCurrentUser } = useContext(UserContext);
|
||||
useEffect(() => {
|
||||
const cleanup = async () => {
|
||||
await makeRequest({
|
||||
url: "http://localhost:5000/logout",
|
||||
method: "POST",
|
||||
});
|
||||
|
||||
await setCurrentUser({});
|
||||
localStorage.removeItem("currentUser");
|
||||
window.location.href = "/login";
|
||||
};
|
||||
cleanup();
|
||||
}, []);
|
||||
|
||||
return <div></div>;
|
||||
};
|
||||
|
||||
export default LogoutPage;
|
||||
Reference in New Issue
Block a user