chatbot-template/components/login-button.tsx

42 lines
898 B
TypeScript
Raw Normal View History

2023-06-13 18:14:06 +04:00
'use client'
import * as React from 'react'
import { cn } from '@/lib/utils'
import { Button, type ButtonProps } from '@/components/ui/button'
import { IconGitHub, IconSpinner } from '@/components/ui/icons'
2023-06-13 17:31:15 -04:00
import { useClerk } from '@clerk/nextjs'
2023-06-13 18:14:06 +04:00
interface LoginButtonProps extends ButtonProps {
text?: string
}
export function LoginButton({
className,
text = 'Login with GitHub',
...props
}: LoginButtonProps) {
const [isLoading, setIsLoading] = React.useState(false)
2023-06-13 17:31:15 -04:00
const clerk = useClerk()
2023-06-13 18:14:06 +04:00
return (
<Button
variant="outline"
onClick={() => {
setIsLoading(true)
2023-06-13 17:31:15 -04:00
clerk.openSignIn({})
2023-06-13 18:14:06 +04:00
}}
disabled={isLoading}
className={cn(className)}
{...props}
>
{isLoading ? (
<IconSpinner className="mr-2 animate-spin" />
) : (
<IconGitHub className="mr-2" />
)}
{text}
</Button>
)
}