added spinner to signin button
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 2m28s
All checks were successful
Vercel Production Deployment / Deploy-Production (push) Successful in 2m28s
This commit is contained in:
parent
6f18a4cb48
commit
3370ab6a03
@ -1,32 +1,48 @@
|
||||
"use client";
|
||||
|
||||
import { signIn, signOut } from "next-auth/react";
|
||||
import { SyntheticEvent } from "react";
|
||||
import { SyntheticEvent, useState } from "react";
|
||||
import { Session } from "next-auth";
|
||||
import { Button } from "@nextui-org/button";
|
||||
import { Spinner } from "@nextui-org/react";
|
||||
|
||||
interface SignInProps {
|
||||
session: Session | null;
|
||||
}
|
||||
|
||||
export default function SignIn({ session }: SignInProps) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const handleSignIn = async (event: SyntheticEvent) => {
|
||||
event.preventDefault();
|
||||
setLoading(true);
|
||||
await signIn("github");
|
||||
};
|
||||
|
||||
const handleSignOut = async (event: SyntheticEvent) => {
|
||||
event.preventDefault();
|
||||
setLoading(true);
|
||||
await signOut();
|
||||
};
|
||||
|
||||
return session?.user ? (
|
||||
<form onSubmit={handleSignOut}>
|
||||
<Button type="submit">Sign out</Button>
|
||||
</form>
|
||||
) : (
|
||||
<form onSubmit={handleSignIn}>
|
||||
<Button type="submit">Sign in</Button>
|
||||
</form>
|
||||
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>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user