Skip to content

Commit 50089d4

Browse files
chore: 🤖 add Logout handle (broken not working properly)
1 parent 5f0bb3d commit 50089d4

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Diff for: components/dashboardComponents/AppSidebar.tsx

+19-2
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,29 @@ import {
99
ChevronLeft,
1010
} from "lucide-react";
1111
import { useTheme } from "next-themes";
12-
import { usePathname } from "next/navigation";
12+
import { useRouter, usePathname } from "next/navigation";
1313
import Link from "next/link";
1414

1515
import { Button } from "@/components/ui/button";
1616
import { cn } from "@/lib/utils";
1717
import { SidebarData } from "@/data/SidebarData";
18+
import { supabase } from "@/lib/supabaseClient";
1819

1920
export function AppSidebar() {
2021
const { setTheme, theme } = useTheme();
2122
const pathname = usePathname();
23+
const router = useRouter();
2224
const [isCollapsed, setIsCollapsed] = React.useState(false);
25+
const handleLogout = async () => {
26+
try {
27+
const { error } = await supabase.auth.signOut();
28+
if (error) throw error;
29+
router.push('/auth/signin');
30+
} catch (error) {
31+
console.error("Sign out error:", error);
32+
}
33+
// Fix the Logout functionality, something is wrong here, It keeps throwing a 307 error on logout,and the user is not redirected to the login page
34+
};
2335

2436
return (
2537
<aside
@@ -85,7 +97,12 @@ export function AppSidebar() {
8597
<Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
8698
<span className="sr-only">Toggle theme</span>
8799
</Button>
88-
<Button variant="outline" size="icon">
100+
<Button
101+
variant="outline"
102+
size="icon"
103+
onClick={handleLogout}
104+
className="rounded-full"
105+
>
89106
<LogOut className="h-[1.2rem] w-[1.2rem]" />
90107
<span className="sr-only">Logout</span>
91108
</Button>

0 commit comments

Comments
 (0)