moved sign-in component to a proper folder
This commit is contained in:
40
src/components/sign-in.tsx
Normal file
40
src/components/sign-in.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
"use client"
|
||||
|
||||
import { signOut, useSession } from "next-auth/react"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { useRouter } from "next/navigation"
|
||||
|
||||
export default function SignIn() {
|
||||
const { data: session, status } = useSession()
|
||||
const router = useRouter()
|
||||
|
||||
const handleSignOut = async () => {
|
||||
await signOut({ redirect: false })
|
||||
router.push("/")
|
||||
router.refresh()
|
||||
}
|
||||
|
||||
if (status === "loading") {
|
||||
return <div className="h-8 w-16 bg-muted animate-pulse rounded"></div>
|
||||
}
|
||||
|
||||
if (session?.user) {
|
||||
return (
|
||||
<div className="flex items-center gap-4">
|
||||
<Button onClick={handleSignOut} variant="ghost" size="default">
|
||||
Sign Out
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Button
|
||||
onClick={() => router.push("/auth/signin")}
|
||||
variant="outline"
|
||||
size="default"
|
||||
>
|
||||
Sign In
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user