@@ -9,17 +9,29 @@ import {
9
9
ChevronLeft ,
10
10
} from "lucide-react" ;
11
11
import { useTheme } from "next-themes" ;
12
- import { usePathname } from "next/navigation" ;
12
+ import { useRouter , usePathname } from "next/navigation" ;
13
13
import Link from "next/link" ;
14
14
15
15
import { Button } from "@/components/ui/button" ;
16
16
import { cn } from "@/lib/utils" ;
17
17
import { SidebarData } from "@/data/SidebarData" ;
18
+ import { supabase } from "@/lib/supabaseClient" ;
18
19
19
20
export function AppSidebar ( ) {
20
21
const { setTheme, theme } = useTheme ( ) ;
21
22
const pathname = usePathname ( ) ;
23
+ const router = useRouter ( ) ;
22
24
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
+ } ;
23
35
24
36
return (
25
37
< aside
@@ -85,7 +97,12 @@ export function AppSidebar() {
85
97
< Moon className = "absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
86
98
< span className = "sr-only" > Toggle theme</ span >
87
99
</ Button >
88
- < Button variant = "outline" size = "icon" >
100
+ < Button
101
+ variant = "outline"
102
+ size = "icon"
103
+ onClick = { handleLogout }
104
+ className = "rounded-full"
105
+ >
89
106
< LogOut className = "h-[1.2rem] w-[1.2rem]" />
90
107
< span className = "sr-only" > Logout</ span >
91
108
</ Button >
0 commit comments