mirror of
https://github.com/Ategon/Jamjar.git
synced 2025-02-12 06:16:21 +00:00
Fix logout to actually logout
This commit is contained in:
parent
b816523cf9
commit
7de5732596
2 changed files with 22 additions and 5 deletions
src
|
@ -6,11 +6,28 @@ import { toast } from "react-toastify";
|
||||||
|
|
||||||
export default function UserPage() {
|
export default function UserPage() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
document.cookie = "token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
async function logout() {
|
||||||
|
const response = await fetch(
|
||||||
|
process.env.NEXT_PUBLIC_MODE === "PROD"
|
||||||
|
? "https://d2jam.com/api/v1/logout"
|
||||||
|
: "http://localhost:3005/api/v1/logout",
|
||||||
|
{ method: "POST", credentials: "include" }
|
||||||
|
);
|
||||||
|
|
||||||
toast.success("Successfully logged out");
|
if (response.ok) {
|
||||||
|
document.cookie =
|
||||||
|
"token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
||||||
|
document.cookie =
|
||||||
|
"user=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
||||||
|
|
||||||
redirect("/");
|
toast.success("Successfully logged out");
|
||||||
|
redirect("/");
|
||||||
|
} else {
|
||||||
|
toast.error("Error while trying to log out");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logout();
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -28,7 +28,7 @@ export default function PCNavbarUser({ user }: NavbarUserProps) {
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
key="profile"
|
key="profile"
|
||||||
className="text-black"
|
className="text-[#333] dark:text-white"
|
||||||
href={`/u/${user.slug}`}
|
href={`/u/${user.slug}`}
|
||||||
>
|
>
|
||||||
Profile
|
Profile
|
||||||
|
@ -36,7 +36,7 @@ export default function PCNavbarUser({ user }: NavbarUserProps) {
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
showDivider
|
showDivider
|
||||||
key="settings"
|
key="settings"
|
||||||
className="text-black"
|
className="text-[#333] dark:text-white"
|
||||||
href="/settings"
|
href="/settings"
|
||||||
>
|
>
|
||||||
Settings
|
Settings
|
||||||
|
|
Loading…
Reference in a new issue