mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 04:26:57 +00:00
Sign in mechanism
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
import { signIn, signOut, useSession } from "next-auth/react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
const AuthButton = () => {
|
||||
const t = useTranslations("Nav");
|
||||
const router = useRouter();
|
||||
const [signingOut, setSigningOut] = useState(false);
|
||||
const { data: sessionData } = useSession();
|
||||
|
||||
const handleSignOut = async () => {
|
||||
setSigningOut(true);
|
||||
try {
|
||||
await signOut({ redirect: false });
|
||||
router.push("/");
|
||||
} finally {
|
||||
setSigningOut(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (sessionData) {
|
||||
return (
|
||||
<button disabled={signingOut} onClick={handleSignOut}>
|
||||
{t("signOut")}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
return <button onClick={() => signIn()}>{t("signIn")}</button>;
|
||||
};
|
||||
|
||||
export default AuthButton;
|
||||
Reference in New Issue
Block a user