refactor: refresh profileBar when logout

This commit is contained in:
sirin 2024-10-06 14:10:13 +07:00
parent 10d03da196
commit ca5764fb24

View File

@ -1,15 +1,23 @@
"use client";
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
import { usePathname } from "next/navigation";
import { useRouter } from "next/navigation";
export function LogoutButton() {
const supabase = createSupabaseClient();
const pathname = usePathname();
const router = useRouter();
const handleLogout = async () => {
await supabase.auth.signOut();
router.push("/");
if (pathname === "/") {
window.location.reload();
} else {
await router.push("/");
window.location.reload();
}
};
return <button onClick={handleLogout}>Logout</button>;