titles/components/SignIn.tsx

33 lines
764 B
TypeScript
Raw Permalink Normal View History

2024-05-16 21:23:10 +00:00
"use client";
import { signIn, signOut } from "next-auth/react";
import { SyntheticEvent } from "react";
import { Session } from "next-auth";
2024-05-17 08:44:41 +00:00
import { Button } from "@nextui-org/button";
2024-05-16 21:23:10 +00:00
interface SignInProps {
session: Session | null;
}
2024-05-17 08:44:41 +00:00
export default function SignIn({ session }: SignInProps) {
2024-05-16 21:23:10 +00:00
const handleSignIn = async (event: SyntheticEvent) => {
event.preventDefault();
await signIn("github");
};
const handleSignOut = async (event: SyntheticEvent) => {
event.preventDefault();
await signOut();
};
return session?.user ? (
<form onSubmit={handleSignOut}>
2024-05-17 08:44:41 +00:00
<Button type="submit">Sign out</Button>
</form>
2024-05-16 21:23:10 +00:00
) : (
<form onSubmit={handleSignIn}>
2024-05-17 08:44:41 +00:00
<Button type="submit">Sign in</Button>
2024-05-16 21:23:10 +00:00
</form>
);
}