Skip to content

Commit

Permalink
Fix : 라우터 프로텍터 미적용 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
BearHumanS committed May 14, 2024
1 parent a21479a commit 4cd7691
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/app/RequiredAuth.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use client';

import { useEffect } from 'react';
import useUserStore from '@/store/useUsersStore';
import { useRouter } from 'next/navigation';
import { childrenProps } from '@/lib/type';

const RequiredAuth = ({ children }: childrenProps) => {
const { user } = useUserStore();
const router = useRouter();

useEffect(() => {
if (!user) {
alert('로그인 해주세요.');
router.replace('/');
}
}, [user, router]);
return user ? children : null;
};

export default RequiredAuth;
20 changes: 20 additions & 0 deletions src/app/cardEdit/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { PropsWithChildren } from 'react';
import type { Metadata } from 'next';
import { getMetadata } from '@/lib/util/getMetaData';
import RequiredAuth from '@/app/RequiredAuth';

export const generateMetadata = async (): Promise<Metadata> => {
return getMetadata({
title: `포케허브 | 카드제작`,
});
};

const CardEditLayout = ({ children }: PropsWithChildren) => {
return (
<RequiredAuth>
<div>{children}</div>
</RequiredAuth>
);
};

export default CardEditLayout;
20 changes: 20 additions & 0 deletions src/app/community/add/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { PropsWithChildren } from 'react';
import type { Metadata } from 'next';
import { getMetadata } from '@/lib/util/getMetaData';
import RequiredAuth from '@/app/RequiredAuth';

export const generateMetadata = async (): Promise<Metadata> => {
return getMetadata({
title: `포케허브 | 게시물 작성`,
});
};

const AddLayout = ({ children }: PropsWithChildren) => {
return (
<RequiredAuth>
<div>{children}</div>
</RequiredAuth>
);
};

export default AddLayout;
20 changes: 20 additions & 0 deletions src/app/community/edit/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { PropsWithChildren } from 'react';
import type { Metadata } from 'next';
import { getMetadata } from '@/lib/util/getMetaData';
import RequiredAuth from '@/app/RequiredAuth';

export const generateMetadata = async (): Promise<Metadata> => {
return getMetadata({
title: `포케허브 | 게시물 수정`,
});
};

const EditLayout = ({ children }: PropsWithChildren) => {
return (
<RequiredAuth>
<div>{children}</div>
</RequiredAuth>
);
};

export default EditLayout;
20 changes: 20 additions & 0 deletions src/app/mypage/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { PropsWithChildren } from 'react';
import type { Metadata } from 'next';
import { getMetadata } from '@/lib/util/getMetaData';
import RequiredAuth from '@/app/RequiredAuth';

export const generateMetadata = async (): Promise<Metadata> => {
return getMetadata({
title: `포케허브 | 마이페이지`,
});
};

const MypageLayout = ({ children }: PropsWithChildren) => {
return (
<RequiredAuth>
<div>{children}</div>
</RequiredAuth>
);
};

export default MypageLayout;

0 comments on commit 4cd7691

Please sign in to comment.