2024-05-16 21:23:10 +00:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
import { signIn, signOut } from "next-auth/react";
|
2024-05-17 21:22:31 +00:00
|
|
|
import { SyntheticEvent, useState } from "react";
|
2024-05-16 21:23:10 +00:00
|
|
|
import { Session } from "next-auth";
|
2024-05-17 08:44:41 +00:00
|
|
|
import { Button } from "@nextui-org/button";
|
2024-05-17 21:22:31 +00:00
|
|
|
import { Spinner } from "@nextui-org/react";
|
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-17 21:22:31 +00:00
|
|
|
const [loading, setLoading] = useState(false);
|
2024-05-16 21:23:10 +00:00
|
|
|
const handleSignIn = async (event: SyntheticEvent) => {
|
|
|
|
event.preventDefault();
|
2024-05-17 21:22:31 +00:00
|
|
|
setLoading(true);
|
2024-05-16 21:23:10 +00:00
|
|
|
await signIn("github");
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleSignOut = async (event: SyntheticEvent) => {
|
|
|
|
event.preventDefault();
|
2024-05-17 21:22:31 +00:00
|
|
|
setLoading(true);
|
2024-05-16 21:23:10 +00:00
|
|
|
await signOut();
|
|
|
|
};
|
|
|
|
|
2024-05-17 21:22:31 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{session?.user ? (
|
|
|
|
<form onSubmit={handleSignOut}>
|
|
|
|
<Button type="submit" disabled={loading}>
|
|
|
|
Sign out
|
|
|
|
</Button>
|
|
|
|
</form>
|
|
|
|
) : (
|
|
|
|
<form onSubmit={handleSignIn}>
|
|
|
|
{!loading ? (
|
|
|
|
<Button type="submit" disabled={loading}>
|
|
|
|
Sign in
|
|
|
|
</Button>
|
|
|
|
) : (
|
|
|
|
<Spinner color="success" />
|
|
|
|
)}
|
|
|
|
</form>
|
|
|
|
)}
|
|
|
|
</>
|
2024-05-16 21:23:10 +00:00
|
|
|
);
|
|
|
|
}
|