Skip to content

Commit

Permalink
fix: 새로고침했을때 자동 로그인이 되지 않는 버그 수정 (#276)
Browse files Browse the repository at this point in the history
* feat(shelter): 로더 추가

* feat(shared): 자동 로그인 기능 추가
  • Loading branch information
DongjaJ authored Dec 1, 2023
1 parent efcb7e6 commit 8301bd3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/shared/components/Loader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Flex, Spinner } from '@chakra-ui/react';

export default function Loader() {
return (
<Flex justify="center" align="center">
<Spinner
thickness="4px"
speed="0.65s"
emptyColor="gray.200"
color="orange.400"
size="xl"
/>
</Flex>
);
}
10 changes: 9 additions & 1 deletion packages/shared/layout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Box, Container } from '@chakra-ui/react';
import { useEffect } from 'react';
import { useEffect, useState } from 'react';
import { Outlet, useLocation, useNavigate } from 'react-router-dom';

import Loader from '../components/Loader';
import LocalErrorBoundary from '../components/LocalErrorBoundary';
import useAuthStore from '../store/authStore';
import { AppType } from '../types/app';
Expand All @@ -20,6 +21,7 @@ export default function Layout({ appType }: LayoutProps) {
const navigate = useNavigate();
const { pathname } = useLocation();
const { setUser } = useAuthStore();
const [isLoading, setIsLoading] = useState(true);

useEffect(() => {
try {
Expand All @@ -36,6 +38,8 @@ export default function Layout({ appType }: LayoutProps) {
if (pathname === '/') {
navigate('/signin');
}
} finally {
setIsLoading(false);
}

//TODO 액세스 토큰 갱신 api 정상화 되면 연결
Expand All @@ -59,6 +63,10 @@ export default function Layout({ appType }: LayoutProps) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

if (isLoading) {
return <Loader />;
}

return (
<Container pos="relative" maxW="container.sm" h="100vh" p={0} centerContent>
<Header appType={appType} />
Expand Down

0 comments on commit 8301bd3

Please sign in to comment.