"use client"; import { useEffect, useState } from "react"; import { useRouter, useSearchParams } from "next/navigation"; import { useAuth } from "@/contexts/auth-context"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; export default function AuthCallbackPage() { const router = useRouter(); const searchParams = useSearchParams(); const { login } = useAuth(); const [error, setError] = useState(null); const [isProcessing, setIsProcessing] = useState(true); useEffect(() => { const processCallback = async () => { // Get token from URL fragment (hash) const hash = window.location.hash.substring(1); // Remove the # const params = new URLSearchParams(hash); const token = params.get("token"); if (!token) { setError("Missing authentication token"); setIsProcessing(false); return; } try { // Store the token and decode user info from JWT await login(token); setIsProcessing(false); } catch (err) { setError("Failed to complete authentication"); setIsProcessing(false); } }; processCallback(); }, [searchParams, login]); if (error) { return (
Authentication Error {error}
); } return (
Authenticating... Please wait while we complete your login.
); }