Skip to content

Commit

Permalink
Feat: #80 refresh token 갱신 모킹 함수 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoonyesol committed Aug 26, 2024
1 parent 7158db1 commit 571d047
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import ReactDOM from 'react-dom/client';
import '@/globals.css';
import MainRouter from '@routes/MainRouter.tsx';
import { CookiesProvider } from 'react-cookie';

async function enableMocking() {
if (!import.meta.env.DEV) return;
Expand All @@ -14,9 +13,7 @@ async function enableMocking() {
enableMocking().then(() => {
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<CookiesProvider>
<MainRouter />
</CookiesProvider>
<MainRouter />
</React.StrictMode>,
);
});
17 changes: 17 additions & 0 deletions src/mocks/services/authServiceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ const authServiceHandler = [
}
return new HttpResponse(JSON.stringify({ message: '아이디 또는 비밀번호가 잘못되었습니다.' }), { status: 400 });
}),
// refresh token 갱신 API
http.post(`${BASE_URL}/user/login/refresh`, async ({ cookies }) => {
const { refreshToken } = cookies;

if (refreshToken === 'mockedRefreshToken') {
const newAccessToken = 'newMockedAccessToken';

return new HttpResponse(null, {
status: 200,
headers: {
Authorization: `Bearer ${newAccessToken}`,
'Set-Cookie': `refreshToken=${refreshToken}`,
},
});
}
return new HttpResponse(JSON.stringify({ message: '리프레시 토큰이 유효하지 않습니다.' }), { status: 400 });
}),
];

export default authServiceHandler;

0 comments on commit 571d047

Please sign in to comment.