layout.tsx 656 B

123456789101112131415161718192021222324252627
  1. 'use client';
  2. import './style.scss';
  3. import { useRouter } from 'next/navigation';
  4. import { useEffect } from 'react';
  5. import Layout from "@/app/component/Layout";
  6. import useAuth from '@/hooks/useAuth';
  7. export default function AccountLayout({ children }: { children: React.ReactNode }) {
  8. const router = useRouter();
  9. const { isAuthenticated, isLoading } = useAuth();
  10. // 로그인 만료 시 홈으로 리다이렉트
  11. useEffect(() => {
  12. if (!isLoading && !isAuthenticated) {
  13. router.replace('/');
  14. }
  15. }, [isAuthenticated, isLoading, router]);
  16. if (isLoading || !isAuthenticated) {
  17. return null;
  18. }
  19. return (
  20. <Layout>{children}</Layout>
  21. );
  22. }