Skip to content

Commit

Permalink
feat: 비인증 회원 로그인 페이지로 이동 기능 추가 #223
Browse files Browse the repository at this point in the history
  • Loading branch information
bottlewook committed Feb 28, 2024
1 parent b0d4958 commit 1d5ba91
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/hooks/withAuth.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { ComponentType } from 'react';
import { ComponentType, useEffect } from 'react';

import { useRouter } from 'next/navigation';

Expand All @@ -15,10 +15,16 @@ function withAuth<Props = Record<string, never>>(
(prev, curr) => { return prev === curr; },
);

useEffect(() => {
if (userId == null) {
router.push('/login');
}
}, [userId, router]);

if (userId == null) {
router.push('/');
return null;
}

return <WrappedComponent {...(props as any)} />;
};
}
Expand Down

0 comments on commit 1d5ba91

Please sign in to comment.