Skip to content

Commit

Permalink
πŸ›  fix(#168): λ¦¬λ‹€μ΄λ ‰νŠΈ μˆ˜μ • (λžœλ”©, 404)
Browse files Browse the repository at this point in the history
- λžœλ”©: 둜그인 μƒνƒœμΌλ•Œ λͺ¨λ‹¬ 없이 λ°”λ‘œ λ‚˜μ˜ λŒ€μ‹œλ³΄λ“œλ‘œ
- 404: 3초 λ’€ 둜그인 여뢀에 따라 λžœλ”© or λ‚˜μ˜ λŒ€μ‹œλ³΄λ“œλ‘œ
  • Loading branch information
un0211 committed Jul 6, 2024
1 parent 4f0fe33 commit 37fc272
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/Redirect/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import { useRouter } from 'next/router';
import { useSelector } from 'react-redux';

import useRedirectIfAuth from '@/hooks/useRedirectIfAuth';
import useRedirectIfNotAuth from '@/hooks/useRedirectIfNotAuth';
import { RootState } from '@/store/store';

export default function Redirect({ children }: { children: React.ReactNode }) {
const router = useRouter();
const { user } = useSelector((state: RootState) => state.user);
const currentPath = router.pathname;

const redirectIfAuth = useRedirectIfAuth();
const redirectIfNotAuth = useRedirectIfNotAuth();

if (['/', '/signup', '/signin'].includes(currentPath)) {
if (currentPath === '/' && user) {
router.replace('/mydashboard');
}

if (currentPath === '/404') {
const nextPath = user ? '/mydashboard' : '/';
setTimeout(() => router.push(nextPath), 3000);
}

if (['/signup', '/signin'].includes(currentPath)) {
const isRedirecting = redirectIfAuth();
if (isRedirecting) {
return <></>;
Expand Down

0 comments on commit 37fc272

Please sign in to comment.