import { useRouter, useSearchParams, usePathname } from "next/navigation"; import { useEffect, useState } from "react"; export default function Index() { const [data, setData] = useState(""); const router = useRouter(); const searchParams = useSearchParams(); const pathname = usePathname(); const appSlug = searchParams.get("appSlug"); const userId = searchParams.get("userId"); useEffect(() => { let isRedirectNeeded = false; const newSearchParams = new URLSearchParams(new URL(document.URL).searchParams); if (!userId) { newSearchParams.set("userId", "1"); isRedirectNeeded = true; } if (!appSlug) { newSearchParams.set("appSlug", "google-calendar"); isRedirectNeeded = true; } if (isRedirectNeeded) { router.push(`${pathname}?${newSearchParams.toString()}`); } }, [router, pathname, userId, appSlug]); async function updateToken({ invalid } = { invalid: false }) { const res = await fetch( `/api/setTokenInCalCom?invalid=${invalid ? 1 : 0}&userId=${userId}&appSlug=${appSlug}`, { method: "GET", headers: { "Content-Type": "application/json", }, } ); const data = await res.json(); setData(JSON.stringify(data)); } return (

Welcome to Credential Sync Playground

You are managing credentials for cal.com userId={userId} for{" "} appSlug={appSlug}. Update query params to manage a different user or app{" "}

{data}
); }