"use client"; import { useEffect, useRef, useState } from "react"; import { useRouter } from "next/navigation"; import { useSupabase } from "@/app/supabase-provider"; import Toast, { ToastRef } from "@/app/components/ui/Toast"; import PageHeading from "@/app/components/ui/PageHeading"; import Button from "@/app/components/ui/Button"; import Card from "@/app/components/ui/Card"; import Link from "next/link"; export default function Logout() { const { supabase } = useSupabase(); const [isPending, setIsPending] = useState(false); const logoutToast = useRef(null); const [error, setError] = useState("Unknown Error"); const router = useRouter(); const handleLogout = async () => { setIsPending(true); const { error } = await supabase.auth.signOut(); if (error) { console.error("Error logging out:", error.message); setError(error.message); logoutToast.current?.publish({ variant: "danger", text: `Error logging out: ${error.message}`, }); } else { console.log("User logged out"); logoutToast.current?.publish({ variant: "success", text: "Logged out successfully", }); router.replace("/"); } setIsPending(false); }; // useEffect(() => { // handleLogout(); // }, []); return (

Are you sure you want to sign out?

Logged Out Successfully {error}
); }