Fix logout to actually logout

This commit is contained in:
Ategon 2025-01-19 20:18:47 -05:00
parent b816523cf9
commit 7de5732596
2 changed files with 22 additions and 5 deletions

View file

@ -6,11 +6,28 @@ import { toast } from "react-toastify";
export default function UserPage() {
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 (

View file

@ -28,7 +28,7 @@ export default function PCNavbarUser({ user }: NavbarUserProps) {
<DropdownMenu>
<DropdownItem
key="profile"
className="text-black"
className="text-[#333] dark:text-white"
href={`/u/${user.slug}`}
>
Profile
@ -36,7 +36,7 @@ export default function PCNavbarUser({ user }: NavbarUserProps) {
<DropdownItem
showDivider
key="settings"
className="text-black"
className="text-[#333] dark:text-white"
href="/settings"
>
Settings