fixed refresh token expire.
All checks were successful
Build And Test / build-and-push (push) Successful in 1m22s

This commit is contained in:
2025-06-17 13:24:46 +09:00
parent 210bf24e45
commit 6cb8796d5c
6 changed files with 116 additions and 114 deletions

View File

@ -1,70 +1,7 @@
# Getting Started with Create React App # msa-fe
## RELEASE
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). ### 0.0.17-rc4
* refresh token 없으면 자동 로그아웃 되도록 변경.
## Available Scripts * lucide-react 라이브러리 추가.
```npm install lucide-react```
In the project directory, you can run: * Navbar 반응형 적용
### `npm start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
The page will reload when you make changes.\
You may also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
### Analyzing the Bundle Size
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
### Making a Progressive Web App
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
### Advanced Configuration
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
### Deployment
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
### `npm run build` fails to minify
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)

10
package-lock.json generated
View File

@ -15,6 +15,7 @@
"@testing-library/user-event": "^13.5.0", "@testing-library/user-event": "^13.5.0",
"axios": "^1.8.4", "axios": "^1.8.4",
"echarts": "^5.6.0", "echarts": "^5.6.0",
"lucide-react": "^0.516.0",
"react": "^19.1.0", "react": "^19.1.0",
"react-dom": "^19.1.0", "react-dom": "^19.1.0",
"react-router-dom": "^7.5.1", "react-router-dom": "^7.5.1",
@ -11302,6 +11303,15 @@
"yallist": "^3.0.2" "yallist": "^3.0.2"
} }
}, },
"node_modules/lucide-react": {
"version": "0.516.0",
"resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-0.516.0.tgz",
"integrity": "sha512-aybBJzLHcw1CIn3rUcRkztB37dsJATtpffLNX+0/w+ws2p21nYIlOwX/B5fqxq8F/BjqVemnJX8chKwRidvROg==",
"license": "ISC",
"peerDependencies": {
"react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0"
}
},
"node_modules/lz-string": { "node_modules/lz-string": {
"version": "1.5.0", "version": "1.5.0",
"resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.5.0.tgz", "resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.5.0.tgz",

View File

@ -10,6 +10,7 @@
"@testing-library/user-event": "^13.5.0", "@testing-library/user-event": "^13.5.0",
"axios": "^1.8.4", "axios": "^1.8.4",
"echarts": "^5.6.0", "echarts": "^5.6.0",
"lucide-react": "^0.516.0",
"react": "^19.1.0", "react": "^19.1.0",
"react-dom": "^19.1.0", "react-dom": "^19.1.0",
"react-router-dom": "^7.5.1", "react-router-dom": "^7.5.1",

View File

@ -15,22 +15,31 @@ export const attachAuthInterceptors = (axiosInstance, logout) => {
async err => { async err => {
const originalRequest = err.config; const originalRequest = err.config;
if ( const is401 = err.response?.status === 401;
err.response?.status === 401 && const hasRefresh = !!localStorage.getItem('refresh');
!originalRequest._retry &&
localStorage.getItem('refresh')
) {
originalRequest._retry = true;
try { console.log("📌 401 감지됨?", is401);
const newAccess = await refreshAccessToken(); console.log("📌 refresh 있음?", hasRefresh);
originalRequest.headers.Authorization = `Bearer ${newAccess}`; console.log("📌 originalRequest._retry", originalRequest._retry);
return axiosInstance(originalRequest);
} catch (refreshError) { if (is401 && !originalRequest._retry) {
console.error('토큰 갱신 실패', refreshError); if (hasRefresh) {
if (logout) logout(); // ✅ Context logout 반영 originalRequest._retry = true;
window.location.href = '/login'; try {
const newAccess = await refreshAccessToken();
originalRequest.headers.Authorization = `Bearer ${newAccess}`;
return axiosInstance(originalRequest);
} catch (refreshError) {
console.error("❌ 토큰 갱신 실패", refreshError);
}
} }
// ✅ refresh 없거나, 갱신 실패 시 모두 여기서 logout
console.warn("❌ refresh 없음 또는 갱신 실패 - 로그아웃 진행");
localStorage.removeItem('access');
localStorage.removeItem('refresh');
logout?.();
window.location.href = '/login';
} }
return Promise.reject(err); return Promise.reject(err);

View File

@ -1,11 +1,13 @@
import React from "react"; import React, { useState } from "react";
import { Link, useNavigate, useLocation } from "react-router-dom"; import { Link, useNavigate, useLocation } from "react-router-dom";
import { useAuth } from "../context/AuthContext"; import { useAuth } from "../context/AuthContext";
import { Menu, X } from "lucide-react";
const Navbar = () => { const Navbar = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const location = useLocation(); const location = useLocation();
const { isLoggedIn, logout, user } = useAuth(); const { isLoggedIn, logout, user } = useAuth();
const [mobileOpen, setMobileOpen] = useState(false);
const isHome = location.pathname === "/"; const isHome = location.pathname === "/";
@ -14,66 +16,109 @@ const Navbar = () => {
{ name: "about", path: "/about" }, { name: "about", path: "/about" },
{ name: "posts", path: "/posts" }, { name: "posts", path: "/posts" },
{ name: "boards", path: "/boards" }, { name: "boards", path: "/boards" },
...(isLoggedIn ? [ ...(isLoggedIn
{ name: "tasks", path: "/tasks" }, ? [
{ name: "ansible", path: "/ansible" }, { name: "tasks", path: "/tasks" },
] : []), { name: "ansible", path: "/ansible" },
]
: []),
]; ];
return ( return (
<nav className={`fixed top-0 w-full z-50 h-16 ${isHome ? "text-white bg-transparent" : "text-black bg-white shadow"}`}> <nav className={`fixed top-0 w-full z-50 h-16 ${isHome ? "text-white bg-transparent" : "text-black bg-white shadow"}`}>
<div className="container mx-auto px-4 py-3 flex justify-between items-center"> <div className="container mx-auto px-4 py-3 flex justify-between items-center">
{/* 로고 */}
<Link to="/" className="text-xl font-bold tracking-wide"> <Link to="/" className="text-xl font-bold tracking-wide">
ICURFER ICURFER
</Link> </Link>
<div className="hidden md:flex space-x-6 font-semibold">
{/* ✅ 메뉴 (lg 이상만 보임) */}
<div className="hidden lg:flex space-x-6 font-semibold">
{menuItems.map((item) => ( {menuItems.map((item) => (
<Link <Link
key={item.name} key={item.name}
to={item.path} to={item.path}
className={`hover:text-yellow-400 transition capitalize`} className="hover:text-yellow-400 transition capitalize"
> >
{item.name} {item.name}
</Link> </Link>
))} ))}
</div> </div>
<div className="space-x-2 flex items-center ">
{/* ✅ 우측 로그인/로그아웃 버튼 (lg 이상만 보임) */}
<div className="hidden lg:flex space-x-2 items-center">
{isLoggedIn ? ( {isLoggedIn ? (
<> <>
<Link <Link to="/profile" className={`px-4 py-2 rounded-full shadow ${isHome ? "bg-white text-black" : "bg-gray-200 text-gray-800"}`}>
to="/profile"
className={`px-4 py-2 rounded-full shadow ${isHome ? "bg-white text-black" : "bg-gray-200 text-gray-800"}`}
>
정보 | 등급: {user?.grade && `(${user.grade})`} 정보 | 등급: {user?.grade && `(${user.grade})`}
</Link> </Link>
<button <button onClick={() => { logout(); navigate("/login"); }} className={`px-4 py-2 rounded-full ${isHome ? "bg-white text-black" : "bg-gray-200 text-gray-800"} hover:bg-gray-300`}>
onClick={() => {
logout();
navigate("/login");
}}
className={`px-4 py-2 rounded-full ${isHome ? "bg-white text-black" : "bg-gray-200 text-gray-800"} hover:bg-gray-300`}
>
로그아웃 로그아웃
</button> </button>
</> </>
) : ( ) : (
<> <>
<Link <Link to="/login" className={`px-4 py-2 rounded-full ${isHome ? "bg-gray-200 text-gray-700 hover:bg-gray-300" : "bg-blue-600 text-white"}`}>
to="/login"
className={`px-4 py-2 rounded-full ${isHome ? "bg-gray-200 text-gray-700 hover:bg-gray-300" : "bg-blue-600 text-white"}`}
>
로그인 로그인
</Link> </Link>
<Link <Link to="/register" className={`px-4 py-2 rounded-full ${isHome ? "bg-gray-700 text-white hover:bg-gray-300" : "bg-gray-200 text-gray-800"}`}>
to="/register"
className={`px-4 py-2 rounded-full ${isHome ? "bg-gray-700 text-white hover:bg-gray-300" : "bg-gray-200 text-gray-800"}`}
>
회원가입 회원가입
</Link> </Link>
</> </>
)} )}
</div> </div>
{/* ✅ 모바일 햄버거 아이콘 (lg 미만일 때 보임) */}
<div className="lg:hidden">
<button onClick={() => setMobileOpen(!mobileOpen)}>
{mobileOpen ? <X size={24} /> : <Menu size={24} />}
</button>
</div>
</div> </div>
{/* ✅ 모바일 메뉴 드롭다운 */}
{mobileOpen && (
<div className="lg:hidden bg-white shadow px-4 pt-4 pb-6 space-y-4">
{menuItems.map((item) => (
<Link
key={item.name}
to={item.path}
className="block text-gray-800 font-medium"
onClick={() => setMobileOpen(false)}
>
{item.name}
</Link>
))}
<div className="flex flex-col space-y-2">
{isLoggedIn ? (
<>
<Link to="/profile" onClick={() => setMobileOpen(false)} className="bg-gray-100 px-4 py-2 rounded">
정보 | 등급: {user?.grade && `(${user.grade})`}
</Link>
<button
onClick={() => {
logout();
navigate("/login");
setMobileOpen(false);
}}
className="bg-gray-200 px-4 py-2 rounded hover:bg-gray-300"
>
로그아웃
</button>
</>
) : (
<>
<Link to="/login" onClick={() => setMobileOpen(false)} className="bg-blue-600 text-white px-4 py-2 rounded">
로그인
</Link>
<Link to="/register" onClick={() => setMobileOpen(false)} className="bg-gray-100 text-gray-800 px-4 py-2 rounded">
회원가입
</Link>
</>
)}
</div>
</div>
)}
</nav> </nav>
); );
}; };

View File

@ -1 +1 @@
0.0.17-rc3 0.0.17-rc4