logout/login from anywhere

This commit is contained in:
Oliver Bryan
2025-12-22 06:36:14 +00:00
parent e550b936e0
commit bba672a020
3 changed files with 4 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import LogOutButton from "./components/log-out-button";
function Test() { function Test() {
return ( return (
@@ -9,6 +10,7 @@ function Test() {
<div className="flex gap-4"> <div className="flex gap-4">
<Button linkTo="/">go back to "/"</Button> <Button linkTo="/">go back to "/"</Button>
</div> </div>
<LogOutButton />
</main> </main>
); );
} }

View File

@@ -5,7 +5,7 @@ export default function LogOutButton() {
const logOut = () => { const logOut = () => {
localStorage.removeItem("token"); localStorage.removeItem("token");
localStorage.removeItem("user"); localStorage.removeItem("user");
window.location.href = "/"; window.location.href = "";
}; };
return ( return (

View File

@@ -69,7 +69,7 @@ export default function LogInForm() {
const data = await res.json(); const data = await res.json();
localStorage.setItem("token", data.token); localStorage.setItem("token", data.token);
localStorage.setItem("user", data.user); localStorage.setItem("user", data.user);
window.location.href = "/"; window.location.href = "";
} }
// unauthorized // unauthorized
else if (res.status === 401) { else if (res.status === 401) {