Skip to content

Commit

Permalink
Feat/44 signin route (#49)
Browse files Browse the repository at this point in the history
* feat: rootpage 에서 accessToken 없을때, signin page 로 navigate

* feat: logout api 부재로 임시 함수로 accessToken remove

* feat: refresh token 로직 변경

* feat: signin 수정 완료
  • Loading branch information
eastfilmm authored Jun 6, 2024
1 parent 9fe4bed commit dd6f1b1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/apis/auth/auth.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,18 @@ export async function authApi(
throw error;
}
}

export async function logout(): Promise<AuthAPIRequest> {
try {
const response = await axios.post(`${BASE_URI}/users/signout`, {
withCredentials: true,
});
localStorage.removeItem('accessToken');
localStorage.removeItem('refreshToken');
console.log('sign out successfully');
return response.data;
} catch (error) {
console.error('Error during sign out:', error);
throw error;
}
}
9 changes: 7 additions & 2 deletions src/components/common/header/HeaderSubMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Typography, Space, Dropdown, Menu } from 'antd';
import { Typography, Space, Dropdown, Menu, message } from 'antd';
import { useRecoilState } from 'recoil';

import {
Expand All @@ -11,19 +11,24 @@ import {
selectedInviteModalState,
} from '@finnect/atoms/header/useHeaderMenu';
import InviteModal from '@finnect/components/common/modal/header/InviteModal';
import { logout } from '@finnect/apis/auth/auth.api';
import { useNavigate } from 'react-router-dom';

const { Text } = Typography;

const HeaderSubMenu = () => {
const navigate = useNavigate();
const [visible, setVisible] = useRecoilState(selectedHeaderMenuState);
const [inviteModalVisible, setInviteModalVisible] = useRecoilState(
selectedInviteModalState
);

const handleMenuClick = (e: any) => {
if (e.key === 'logout') {
// 로그아웃 처리
logout();
navigate('/signin');
console.log('로그아웃');
return message.success('로그아웃 성공.');
} else if (e.key === 'invite') {
setInviteModalVisible(true);
}
Expand Down
12 changes: 11 additions & 1 deletion src/pages/RootPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Outlet } from 'react-router-dom';
import { useEffect } from 'react';
import { useNavigate, Outlet } from 'react-router-dom';

import { Layout } from 'antd';
import styled from 'styled-components';
Expand All @@ -14,6 +15,15 @@ const CustomLayout = styled(Layout)`
`;

const RootPage = () => {
const navigate = useNavigate();

useEffect(() => {
const accessToken = localStorage.getItem('accessToken');
if (!accessToken) {
navigate('/signin');
}
}, [navigate]);

return (
<CustomLayout>
<Layout style={{ width: '100%', display: 'flex' }}>
Expand Down

0 comments on commit dd6f1b1

Please sign in to comment.