mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-02 03:38:22 +00:00
first commit
This commit is contained in:
49
components/auth/account-popver.tsx
Normal file
49
components/auth/account-popver.tsx
Normal file
@ -0,0 +1,49 @@
|
||||
'use client'
|
||||
import { Button } from "@/components/ui/button"
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover"
|
||||
import { authClient } from "@/lib/auth-client"
|
||||
import type { User } from "better-auth"
|
||||
import { Loader, User as UserIcon } from "lucide-react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { useState } from "react"
|
||||
|
||||
export function AccountPopover({ user }: { user?: User }) {
|
||||
const [loading, setLoading] = useState(false)
|
||||
const router = useRouter()
|
||||
return (
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<Button variant="outline">
|
||||
<UserIcon />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-80">
|
||||
<div className="grid gap-4">
|
||||
<div className="space-y-2">
|
||||
<h4 className="font-medium leading-none">{user?.name}</h4>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{user?.email}
|
||||
</p>
|
||||
</div>
|
||||
<Button disabled={loading} onClick={async () => {
|
||||
setLoading(true)
|
||||
await authClient.signOut({
|
||||
fetchOptions: {
|
||||
onSuccess: () => {
|
||||
router.push("/login"); // redirect to login page
|
||||
},
|
||||
},
|
||||
})
|
||||
setLoading(false)
|
||||
}}>
|
||||
{loading ? <Loader className="animate-spin" /> : "Logout"}
|
||||
</Button>
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user