mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-02 03:38:22 +00:00
Refactor authentication components and enhance user session handling
- Updated AccountPopover to utilize session data for user information display. - Modified ApplicationLayout to fetch user details from the database using Prisma. - Replaced Checkbox components with native input elements in SignUpForm for better accessibility. - Enhanced seed script to include default islands and create related data in the database.
This commit is contained in:
@ -5,29 +5,38 @@ import {
|
||||
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 { authClient } from "@/lib/auth-client";
|
||||
import type { User } from "@prisma/client";
|
||||
import { Loader2, User as UserIcon } from "lucide-react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { useState } from "react"
|
||||
|
||||
export function AccountPopover({ user }: { user?: User }) {
|
||||
const session = authClient.useSession();
|
||||
const [loading, setLoading] = useState(false)
|
||||
const router = useRouter()
|
||||
|
||||
if (session.isPending) {
|
||||
<Button variant={"outline"} disabled>
|
||||
<Loader2 className="animate-spin" />
|
||||
</Button>
|
||||
}
|
||||
return (
|
||||
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<Button variant="outline">
|
||||
<UserIcon />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-80">
|
||||
<PopoverContent className="w-fit">
|
||||
<div className="grid gap-4">
|
||||
<div className="space-y-2">
|
||||
<h4 className="font-medium leading-none">{user?.name}</h4>
|
||||
<h4 className="font-medium leading-none">{session.data?.user?.name}</h4>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{user?.email}
|
||||
{session.data?.user?.phoneNumber}
|
||||
</p>
|
||||
<span className="text-xs text-gray-500">{user?.address}</span>
|
||||
</div>
|
||||
<Button disabled={loading} onClick={async () => {
|
||||
setLoading(true)
|
||||
@ -40,7 +49,7 @@ export function AccountPopover({ user }: { user?: User }) {
|
||||
})
|
||||
setLoading(false)
|
||||
}}>
|
||||
{loading ? <Loader className="animate-spin" /> : "Logout"}
|
||||
{loading ? <Loader2 className="animate-spin" /> : "Logout"}
|
||||
</Button>
|
||||
</div>
|
||||
</PopoverContent>
|
||||
|
Reference in New Issue
Block a user