mirror of
https://github.com/leonvanzyl/agentic-coding-starter-kit.git
synced 2026-01-31 06:42:07 +00:00
Init
This commit is contained in:
29
src/components/auth/sign-in-button.tsx
Normal file
29
src/components/auth/sign-in-button.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
"use client"
|
||||
|
||||
import { signIn, useSession } from "@/lib/auth-client"
|
||||
import { Button } from "@/components/ui/button"
|
||||
|
||||
export function SignInButton() {
|
||||
const { data: session, isPending } = useSession()
|
||||
|
||||
if (isPending) {
|
||||
return <Button disabled>Loading...</Button>
|
||||
}
|
||||
|
||||
if (session) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<Button
|
||||
onClick={async () => {
|
||||
await signIn.social({
|
||||
provider: "google",
|
||||
callbackURL: "/dashboard",
|
||||
})
|
||||
}}
|
||||
>
|
||||
Sign in with Google
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
33
src/components/auth/sign-out-button.tsx
Normal file
33
src/components/auth/sign-out-button.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
"use client"
|
||||
|
||||
import { signOut, useSession } from "@/lib/auth-client"
|
||||
import { Button } from "@/components/ui/button"
|
||||
|
||||
export function SignOutButton() {
|
||||
const { data: session, isPending } = useSession()
|
||||
|
||||
if (isPending) {
|
||||
return <Button disabled>Loading...</Button>
|
||||
}
|
||||
|
||||
if (!session) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={async () => {
|
||||
await signOut({
|
||||
fetchOptions: {
|
||||
onSuccess: () => {
|
||||
window.location.href = "/"
|
||||
},
|
||||
},
|
||||
})
|
||||
}}
|
||||
>
|
||||
Sign out
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
40
src/components/auth/user-profile.tsx
Normal file
40
src/components/auth/user-profile.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
"use client"
|
||||
|
||||
import { useSession } from "@/lib/auth-client"
|
||||
import { SignInButton } from "./sign-in-button"
|
||||
import { SignOutButton } from "./sign-out-button"
|
||||
|
||||
export function UserProfile() {
|
||||
const { data: session, isPending } = useSession()
|
||||
|
||||
if (isPending) {
|
||||
return <div>Loading...</div>
|
||||
}
|
||||
|
||||
if (!session) {
|
||||
return (
|
||||
<div className="flex flex-col items-center gap-4 p-6">
|
||||
<h2 className="text-xl font-semibold">Welcome</h2>
|
||||
<p className="text-muted-foreground">Please sign in to continue</p>
|
||||
<SignInButton />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center gap-4 p-6">
|
||||
<div className="text-center">
|
||||
{session.user?.image && (
|
||||
<img
|
||||
src={session.user.image}
|
||||
alt={session.user.name || "User"}
|
||||
className="w-16 h-16 rounded-full mx-auto mb-4"
|
||||
/>
|
||||
)}
|
||||
<h2 className="text-xl font-semibold">{session.user?.name}</h2>
|
||||
<p className="text-muted-foreground">{session.user?.email}</p>
|
||||
</div>
|
||||
<SignOutButton />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user