Skip to content

Commit 8619a77

Browse files
committed
feat: 로그아웃 기능 개발
1 parent 5d62fa6 commit 8619a77

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

src/apis/authApis.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,12 @@ export const searchUser = async (nickname: string) => {
7070

7171
return profiles;
7272
};
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+
};

src/components/common/SideBar/HamburgerButton.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SideBarGroupList from './SideBarGroupList';
33
import SideBarProfile from './SideBarProfile';
44
import { useNavigate } from 'react-router-dom';
55
import { useEffect } from 'react';
6+
import SideBarSignOutButton from '@/components/common/SideBar/SideBarSignOutButton.tsx';
67

78
const HamburgerButton = () => {
89
const { data: user, isLoading, isError } = useGetProfile();
@@ -33,9 +34,12 @@ const HamburgerButton = () => {
3334
</label>
3435
<div className="drawer-side lg:w-80">
3536
<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 />
3943
</ul>
4044
</div>
4145
</div>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}

src/react-queries/useSignOut.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
});

0 commit comments

Comments
 (0)