mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 02:33:01 +00:00
logout/login from anywhere
This commit is contained in:
@@ -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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 (
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user