This commit is contained in:
anonymousratwastaken 2025-12-19 15:37:39 +00:00
parent a548189a8f
commit c6268bf167

View file

@ -1,139 +0,0 @@
'use client'
import { useEffect, useState } from 'react'
import { useRouter, useSearchParams } from 'next/navigation'
import { Loader2 } from 'lucide-react'
export default function AuthCallback() {
const router = useRouter()
const searchParams = useSearchParams()
const [status, setStatus] = useState<'loading' | 'success' | 'error'>('loading')
const [error, setError] = useState<string>('')
useEffect(() => {
const handleCallback = async () => {
try {
const code = searchParams.get('code')
const error = searchParams.get('error')
const errorDescription = searchParams.get('error_description')
if (error) {
setError(errorDescription || error)
setStatus('error')
return
}
if (!code) {
setError('No authorization code received')
setStatus('error')
return
}
// Exchange the authorization code for tokens
const response = await fetch('/api/auth/callback', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ code }),
})
if (!response.ok) {
const errorData = await response.json()
throw new Error(errorData.error || 'Authentication failed')
}
const data = await response.json()
// Store the session/token as needed
if (data.redirect) {
window.location.href = data.redirect
} else {
// Default redirect to dashboard or home
router.push('/')
}
setStatus('success')
} catch (err) {
setError(err instanceof Error ? err.message : 'Authentication failed')
setStatus('error')
}
}
handleCallback()
}, [searchParams, router])
if (status === 'loading') {
return (
<div className="min-h-screen flex items-center justify-center bg-background">
<div className="text-center space-y-4">
<Loader2 className="h-8 w-8 animate-spin mx-auto text-primary" />
<p className="text-muted-foreground">Completing authentication...</p>
</div>
</div>
)
}
if (status === 'error') {
return (
<div className="min-h-screen flex items-center justify-center bg-background">
<div className="text-center space-y-4 max-w-md mx-auto p-6">
<div className="rounded-full bg-destructive/10 p-3 w-fit mx-auto">
<svg
className="h-6 w-6 text-destructive"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg>
</div>
<h2 className="text-xl font-semibold text-foreground">Authentication Failed</h2>
<p className="text-muted-foreground">{error}</p>
<div className="space-y-2">
<button
onClick={() => router.push('/')}
className="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2 w-full"
>
Go to Homepage
</button>
<button
onClick={() => window.location.reload()}
className="inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border border-input bg-background hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2 w-full"
>
Try Again
</button>
</div>
</div>
</div>
)
}
return (
<div className="min-h-screen flex items-center justify-center bg-background">
<div className="text-center space-y-4">
<div className="rounded-full bg-green-100 p-3 w-fit mx-auto">
<svg
className="h-6 w-6 text-green-600"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M5 13l4 4L19 7"
/>
</svg>
</div>
<p className="text-muted-foreground">Authentication successful! Redirecting...</p>
</div>
</div>
)
}