chatbot-template/components/user-menu.tsx

38 lines
841 B
TypeScript
Raw Normal View History

2023-06-07 16:17:59 +04:00
'use client'
import * as React from 'react'
2023-06-07 16:17:59 +04:00
import { signIn } from '@auth/nextjs/client'
import { type Session } from '@auth/nextjs/types'
import { Loader2Icon } from 'lucide-react'
import { Button } from '@/components/ui/button'
2023-06-07 16:17:59 +04:00
export interface UserMenuProps {
session?: Session
2023-06-07 16:17:59 +04:00
}
export function UserMenu({ session }: UserMenuProps) {
const [isLoading, setIsLoading] = React.useState(false)
if (!session?.user) {
2023-06-07 16:17:59 +04:00
return (
<Button
variant="ghost"
size="sm"
onClick={() => {
setIsLoading(true)
signIn('github')
}}
disabled={isLoading}
>
{isLoading && <Loader2Icon className="mr-2 h-4 w-4 animate-spin" />}
2023-06-07 16:17:59 +04:00
Login
</Button>
)
}
return (
<p className="px-2 text-sm font-medium">Logged in as {session.user.name}</p>
)
2023-06-07 16:17:59 +04:00
}