initial commit
This commit is contained in:
47
components/auth/GitHubSignInButton.tsx
Normal file
47
components/auth/GitHubSignInButton.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
'use client'
|
||||
import { useState } from 'react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Github } from 'lucide-react'
|
||||
|
||||
interface GitHubSignInButtonProps {
|
||||
className?: string
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
export function GitHubSignInButton({ className, disabled }: GitHubSignInButtonProps) {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
||||
const handleGitHubSignIn = async () => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
|
||||
// Get GitHub OAuth URL from our API
|
||||
const response = await fetch('/api/auth/github')
|
||||
const data = await response.json()
|
||||
|
||||
if (data.success && data.data.authURL) {
|
||||
// Redirect to GitHub OAuth
|
||||
window.location.href = data.data.authURL
|
||||
} else {
|
||||
console.error('Failed to get GitHub auth URL:', data.error)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('GitHub sign-in error:', error)
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={handleGitHubSignIn}
|
||||
disabled={disabled || isLoading}
|
||||
className={className}
|
||||
>
|
||||
<Github className="w-4 h-4 mr-2" />
|
||||
{isLoading ? 'Signing in...' : 'Continue with GitHub'}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user