| 3 | import { Button } from './ui/button'; |
| 4 | |
| 5 | export function SignUpButton() { |
| 6 | const [isSignedIn, setIsSignedIn] = useState(false); |
| 7 | |
| 8 | useEffect(() => { |
| 9 | const check = async () => { |
| 10 | const response = await fetch( |
| 11 | 'https://api.openpanel.dev/trpc/auth.session', |
| 12 | { credentials: 'include', mode: 'cors' } |
| 13 | ); |
| 14 | const data = await response.json(); |
| 15 | const session = data?.result?.data?.json?.session; |
| 16 | setIsSignedIn(session !== null); |
| 17 | }; |
| 18 | check(); |
| 19 | }, []); |
| 20 | |
| 21 | return ( |
| 22 | <Button asChild> |
| 23 | <Link |
| 24 | className="hidden md:flex" |
| 25 | href={`https://dashboard.openpanel.dev${isSignedIn ? '/' : '/onboarding'}`} |
| 26 | > |
| 27 | {isSignedIn ? 'Dashboard' : 'Sign up'} |
| 28 | </Link> |
| 29 | </Button> |
| 30 | ); |
| 31 | } |