Skip to content

Commit

Permalink
feat: implement logout
Browse files Browse the repository at this point in the history
use api to post logout

#128
  • Loading branch information
seo-wo committed Dec 18, 2023
1 parent 3ef33ac commit 5c21199
Showing 1 changed file with 20 additions and 30 deletions.
50 changes: 20 additions & 30 deletions src/components/utils/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useNavigate } from 'react-router-dom';
import { useSetRecoilState } from 'recoil';
import GlobalLoginState from '@recoil/GlobalLoginState';
import { clearToken, getToken } from '@cert/TokenStorage';
import { removeAuth } from '@cert/AuthStorage';
import { Dropdown } from './Dropdown';
import getAddress from '@globalObj/function/getAddress';
import apiClient from '@service/apiClient';
Expand All @@ -14,36 +15,25 @@ function Navbar() {
const url = `${getAddress()}/auth/google`;

const onClickLogOut = () => {
// apiClient
// .post('/auth/logout')
// .then((res) => {
// console.log('logout', res);
// clearToken();
// setLoginState(() => {
// return {
// id: '',
// isLogin: false,
// isAdmin: false,
// profileUrl: '',
// };
// });
// alert('로그아웃 되셨습니다!');
// navigate('/');
// })
// .catch((err) => {
// console.log('logout error', err);
// });
clearToken();
setLoginState(() => {
return {
id: '',
isLogin: false,
isAdmin: false,
profileUrl: '',
};
});
alert('로그아웃 되셨습니다!');
navigate('/');
apiClient
.post('/auth/logout')
.then((res) => {
removeAuth();
clearToken();
setLoginState(() => {
return {
id: '',
isLogin: false,
isAdmin: false,
profileUrl: '',
};
});
alert('로그아웃 되셨습니다!');
navigate('/');
})
.catch((err) => {
alert('로그아웃에 실패했습니다.');
});
};

const onClickAuthTimeline = () => {
Expand Down

0 comments on commit 5c21199

Please sign in to comment.