"use client"; import { useEffect, Suspense } from "react"; import { useSearchParams } from "next/navigation"; function AuthCallbackContent() { const searchParams = useSearchParams(); useEffect(() => { // Get the redirect URL from query params const redirectUrl = searchParams.get("redirect") || "/account/webinars"; // Check if user is authenticated by fetching session const checkAuth = async () => { try { const res = await fetch("/api/auth/me"); const data = await res.json(); if (data.user) { // User is authenticated, redirect to the specified URL window.location.href = redirectUrl; } else { // Not authenticated, redirect to signin window.location.href = `/signin?redirect=${encodeURIComponent(redirectUrl)}`; } } catch (error) { // Error checking auth, redirect to signin window.location.href = `/signin?redirect=${encodeURIComponent(redirectUrl)}`; } }; checkAuth(); }, [searchParams]); return (
Please wait while we complete your authentication