42 lines
1020 B
TypeScript
42 lines
1020 B
TypeScript
'use client'
|
|
|
|
import { useEffect, useState } from 'react'
|
|
import { useRouter } from 'next/navigation'
|
|
import sdk from '@farcaster/frame-sdk'
|
|
|
|
export default function OnboardingCheck({ children }: { children: React.ReactNode }) {
|
|
const [isReady, setIsReady] = useState(false)
|
|
const router = useRouter()
|
|
|
|
useEffect(() => {
|
|
const checkAccount = async () => {
|
|
try {
|
|
const context = await sdk.context
|
|
|
|
if (!context?.user?.fid) {
|
|
// No Farcaster account, redirect to registration
|
|
router.push('/register')
|
|
return
|
|
}
|
|
|
|
setIsReady(true)
|
|
} catch (error) {
|
|
console.error('Onboarding check failed:', error)
|
|
setIsReady(true) // Continue anyway
|
|
}
|
|
}
|
|
|
|
checkAccount()
|
|
}, [router])
|
|
|
|
if (!isReady) {
|
|
return (
|
|
<div className="min-h-screen bg-gray-900 flex items-center justify-center">
|
|
<div className="text-white text-xl">Loading...</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return <>{children}</>
|
|
}
|