mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-11-18 07:22:06 +00:00
60 lines
1.2 KiB
TypeScript
60 lines
1.2 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
|
|
import { signIn, signOut, useSession } from "next-auth/react";
|
|
import { useTranslations } from "next-intl";
|
|
import { useRouter } from "next/navigation";
|
|
|
|
import { DropdownMenuItem } from "@/components/DropdownMenu";
|
|
|
|
export const useAuthMenuOptions = () => {
|
|
const t = useTranslations("Nav");
|
|
const router = useRouter();
|
|
const [signingOut, setSigningOut] = useState(false);
|
|
const { data: sessionData, status } = useSession();
|
|
|
|
const handleSignOut = async () => {
|
|
setSigningOut(true);
|
|
try {
|
|
await signOut({ redirect: false });
|
|
router.push("/");
|
|
} finally {
|
|
setSigningOut(false);
|
|
}
|
|
};
|
|
|
|
if (status === "loading") {
|
|
return [];
|
|
}
|
|
|
|
if (!sessionData) {
|
|
return [
|
|
{
|
|
title: t("signIn"),
|
|
onClick: () => signIn(),
|
|
},
|
|
];
|
|
}
|
|
|
|
const items: DropdownMenuItem[] = [
|
|
{
|
|
title: t("myZones"),
|
|
onClick: () => router.push("/zones"),
|
|
disabled: signingOut,
|
|
},
|
|
{
|
|
title: t("deleteAccount"),
|
|
onClick: () => router.push("/delete-account"),
|
|
disabled: signingOut,
|
|
},
|
|
{
|
|
title: t("signOut"),
|
|
onClick: handleSignOut,
|
|
disabled: signingOut,
|
|
},
|
|
];
|
|
|
|
return items;
|
|
};
|