File tree Expand file tree Collapse file tree 4 files changed +45
-3
lines changed Expand file tree Collapse file tree 4 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -70,3 +70,12 @@ export const searchUser = async (nickname: string) => {
70
70
71
71
return profiles ;
72
72
} ;
73
+
74
+ export const signOut = async ( ) => {
75
+ const { error } = await supabase . auth . signOut ( ) ;
76
+ if ( error ) {
77
+ throw error ;
78
+ }
79
+
80
+ return true ;
81
+ } ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import SideBarGroupList from './SideBarGroupList';
3
3
import SideBarProfile from './SideBarProfile' ;
4
4
import { useNavigate } from 'react-router-dom' ;
5
5
import { useEffect } from 'react' ;
6
+ import SideBarSignOutButton from '@/components/common/SideBar/SideBarSignOutButton.tsx' ;
6
7
7
8
const HamburgerButton = ( ) => {
8
9
const { data : user , isLoading, isError } = useGetProfile ( ) ;
@@ -33,9 +34,12 @@ const HamburgerButton = () => {
33
34
</ label >
34
35
< div className = "drawer-side lg:w-80" >
35
36
< label htmlFor = "my-drawer-3" aria-label = "close sidebar" className = "drawer-overlay" > </ label >
36
- < ul className = "menu min-h-full w-80 bg-base-200 p-4" >
37
- < SideBarProfile imageUrl = { user ?. image_url ?? null } userName = { user ?. user_name ?? '' } />
38
- < SideBarGroupList userId = { user ?. id ?? '' } />
37
+ < ul className = "menu min-h-full w-80 flex-col justify-between bg-base-200 p-4" >
38
+ < div >
39
+ < SideBarProfile imageUrl = { user ?. image_url ?? null } userName = { user ?. user_name ?? '' } />
40
+ < SideBarGroupList userId = { user ?. id ?? '' } />
41
+ </ div >
42
+ < SideBarSignOutButton />
39
43
</ ul >
40
44
</ div >
41
45
</ div >
Original file line number Diff line number Diff line change
1
+ import { useSignOut } from '@/react-queries/useSignOut.ts' ;
2
+ import { useNavigate } from 'react-router-dom' ;
3
+
4
+ export default function SideBarSignOutButton ( ) {
5
+ const { mutate } = useSignOut ( ) ;
6
+ const navigate = useNavigate ( ) ;
7
+
8
+ const onClick = ( ) => {
9
+ mutate ( undefined , {
10
+ onSuccess : ( ) => {
11
+ navigate ( '/login' ) ;
12
+ } ,
13
+ } ) ;
14
+ } ;
15
+
16
+ return (
17
+ < button onClick = { onClick } className = { 'btn btn-error font-bold' } >
18
+ Sign Out
19
+ </ button >
20
+ ) ;
21
+ }
Original file line number Diff line number Diff line change
1
+ import { useMutation } from '@tanstack/react-query' ;
2
+ import { signOut } from '@/apis/authApis.ts' ;
3
+
4
+ export const useSignOut = ( ) =>
5
+ useMutation ( {
6
+ mutationKey : [ 'signOut' ] ,
7
+ mutationFn : signOut ,
8
+ } ) ;
You can’t perform that action at this time.
0 commit comments