Skip to content

Commit

Permalink
Fix: 전반적인 인증 구조 개편 및 기타 로직 리팩터링 (#87)
Browse files Browse the repository at this point in the history
* Fix: verifyGuard page layout 추가 (#81)

* Refactor: 인증 인가 서버 route 처리 및 서버 컴포넌트 가딩 처리 1단계 작업 (#82)

* WIP: social-login server component 단 처리중

* Fix: social-login server route 처리 및 예외 처리 추가

* Fix: home header 로그인 여부 server component 처리로 전환 (#83)

* Fix: login 유지 서버 처리 추가 및 authProvider 로직 추가, 기타 리팩터링 (#85)

* Fix: useSearchParams build prerendering error (#84)

* Fix: 로그아웃 기능 및 기타 파일명 등 수정 (#86)

* Fix: logout 기능 및 기타 변수명 등 수정

* Fix: rebase 후, 파일 명 수정 반영
  • Loading branch information
minchodang authored Sep 29, 2024
1 parent cf28f4d commit e8627d8
Show file tree
Hide file tree
Showing 31 changed files with 537 additions and 275 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@types/recharts": "^1.8.29",
"axios": "^1.6.7",
"dayjs": "^1.11.11",
"next": "13.5.6",
"next": "14.2.12",
"next-intl": "^3.7.0",
"react": "^18",
"react-cookie": "^7.1.4",
Expand Down
103 changes: 57 additions & 46 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/api/postLogin.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import defaultRequest from '@src/lib/axios/defaultRequest';
import { UserInformationResponse } from '@src/types/api/Signs';
import axios from 'axios';

interface PostLoginBody {
email: string;
password: string;
}

export const postLogin = async (body: PostLoginBody) => {
const data = await defaultRequest.post<UserInformationResponse>('/auth/token', { ...body });
const data = await axios.post<UserInformationResponse>('/api/auth', { ...body });
return data;
};
35 changes: 18 additions & 17 deletions src/app/[locale]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import HomeFooterButton from '@src/components/screens/home/components/HomeFooterButton';
import HomeBody from '@src/components/screens/home/section/HomeBody';
import HomeFooter from '@src/components/screens/home/section/HomeFooter';
import dynamic from 'next/dynamic';
import HomeHeaderButton from '@src/components/screens/home/section/HomeHeaderButton';
import { checkToken } from '@src/lib/server/auth/checkToken';
import { AuthService } from '@src/service/AuthService';
import { cookies } from 'next/headers';

const HomeHeaderButton = dynamic(
() => import('@src/components/screens/home/section/HomeHeaderButton'),
{
ssr: false,
},
);
const HomePage = async () => {
const accessToken = cookies().get('atk')?.value;
const { isLogin } = await checkToken(accessToken);

const HomePage = () => (
<div className="w-screen">
<header className="m-5 flex h-10 flex-row-reverse">
<HomeHeaderButton />
</header>
<HomeBody />
<HomeFooter />
<HomeFooterButton />
</div>
);
return (
<div className="w-screen">
<header className="m-5 flex h-10 flex-row-reverse">
<HomeHeaderButton isLogin={isLogin} />
</header>
<HomeBody />
<HomeFooter />
<HomeFooterButton />
</div>
);
};
export default HomePage;
7 changes: 7 additions & 0 deletions src/app/actions/renewAllCache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use server';

import { revalidatePath } from 'next/cache';

export async function renewAllCache() {
return revalidatePath('/');
}
21 changes: 21 additions & 0 deletions src/app/actions/setAuthCookie.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use server';

import { cookies } from 'next/headers';

export const setAuthCookie = async (token: { atk: string; rtk: string }) => {
await cookies().set('rtk', token.rtk, {
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
maxAge: 60 * 60 * 24 * 14, // 2주
path: '/',
sameSite: 'strict',
});
// Refresh Token을 HttpOnly 쿠키로 설정 (기간 2주)
await cookies().set('atk', token.atk, {
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
maxAge: 60 * 30, // 30분
path: '/',
sameSite: 'strict',
});
};
Loading

0 comments on commit e8627d8

Please sign in to comment.