2024-10-23 12:33:19 -04:00
|
|
|
import Form from 'next/form';
|
|
|
|
|
import Link from 'next/link';
|
2024-10-11 18:00:22 +05:30
|
|
|
|
2024-10-23 12:33:19 -04:00
|
|
|
import { auth, signOut } from '@/app/(auth)/auth';
|
2024-10-11 18:00:22 +05:30
|
|
|
|
2024-10-23 12:33:19 -04:00
|
|
|
import { History } from './history';
|
|
|
|
|
import { ThemeToggle } from './theme-toggle';
|
|
|
|
|
import { Button } from '../ui/button';
|
2024-10-11 18:00:22 +05:30
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
DropdownMenuTrigger,
|
2024-10-23 12:33:19 -04:00
|
|
|
} from '../ui/dropdown-menu';
|
2024-10-11 18:00:22 +05:30
|
|
|
|
|
|
|
|
export const Navbar = async () => {
|
|
|
|
|
let session = await auth();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className="bg-background absolute top-0 left-0 w-dvw py-2 px-3 justify-between flex flex-row items-center z-30">
|
|
|
|
|
<div className="flex flex-row gap-3 items-center">
|
|
|
|
|
<History user={session?.user} />
|
|
|
|
|
<div className="flex flex-row gap-2 items-center">
|
|
|
|
|
<div className="text-sm dark:text-zinc-300">Next.js Chatbot</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{session ? (
|
|
|
|
|
<DropdownMenu>
|
|
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
|
<Button
|
|
|
|
|
className="py-1.5 px-2 h-fit font-normal"
|
|
|
|
|
variant="secondary"
|
|
|
|
|
>
|
|
|
|
|
{session.user?.email}
|
|
|
|
|
</Button>
|
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
|
<DropdownMenuContent align="end">
|
|
|
|
|
<DropdownMenuItem>
|
|
|
|
|
<ThemeToggle />
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem className="p-1 z-50">
|
2024-10-23 12:33:19 -04:00
|
|
|
<Form
|
2024-10-11 18:00:22 +05:30
|
|
|
className="w-full"
|
|
|
|
|
action={async () => {
|
2024-10-23 12:33:19 -04:00
|
|
|
'use server';
|
2024-10-11 18:00:22 +05:30
|
|
|
|
|
|
|
|
await signOut({
|
2024-10-23 12:33:19 -04:00
|
|
|
redirectTo: '/',
|
2024-10-11 18:00:22 +05:30
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<button
|
|
|
|
|
type="submit"
|
|
|
|
|
className="w-full text-left px-1 py-0.5 text-red-500"
|
|
|
|
|
>
|
|
|
|
|
Sign out
|
|
|
|
|
</button>
|
2024-10-23 12:33:19 -04:00
|
|
|
</Form>
|
2024-10-11 18:00:22 +05:30
|
|
|
</DropdownMenuItem>
|
|
|
|
|
</DropdownMenuContent>
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
) : (
|
|
|
|
|
<Button className="py-1.5 px-2 h-fit font-normal" asChild>
|
|
|
|
|
<Link href="/login">Login</Link>
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|