"use client"; import Link from "next/link"; import { useUser } from "@/hooks/useUser"; import { use, useState } from "react"; import { useMount, useTimeoutFn } from "react-use"; import { Button } from "@/components/ui/button"; import { AnimatedBlobs } from "@/components/animated-blobs"; import { useBroadcastChannel } from "@/lib/useBroadcastChannel"; export default function AuthCallback({ searchParams, }: { searchParams: Promise<{ code: string }>; }) { const [showButton, setShowButton] = useState(false); const [isPopupAuth, setIsPopupAuth] = useState(false); const { code } = use(searchParams); const { loginFromCode } = useUser(); const { postMessage } = useBroadcastChannel("auth", () => {}); useMount(async () => { if (code) { const isPopup = window.opener || window.parent !== window; setIsPopupAuth(isPopup); if (isPopup) { postMessage({ type: "user-oauth", code: code, }); setTimeout(() => { if (window.opener) { window.close(); } }, 1000); } else { await loginFromCode(code); } } }); useTimeoutFn(() => setShowButton(true), 7000); return (
🚀
👋
🙌

{isPopupAuth ? "Authentication Complete!" : "Login In Progress..."}

{isPopupAuth ? "You can now close this tab and return to the previous page." : "Wait a moment while we log you in with your code."}

If you are not redirected automatically in the next 5 seconds, please click the button below

{showButton ? ( ) : (

Please wait, we are logging you in...

)}
); }