fix: 로그인 후 사용자 역할 인식 문제 해결
Some checks failed
SonarQube Analysis / SonarQube Scan (push) Has been cancelled
Some checks failed
SonarQube Analysis / SonarQube Scan (push) Has been cancelled
- AuthContext를 통한 통합 인증 상태 관리로 변경 - App.jsx와 AuthContext 간 중복 사용자 상태 관리 제거 - SimpleLogin에서 AuthContext의 login 함수 직접 사용 - 로그인 후 사용자 역할이 즉시 올바르게 인식되도록 개선 - 새로고침 없이도 시스템 관리자 권한 정상 표시 변경사항: - App.jsx: AuthProvider 래퍼 추가, 중복 인증 로직 제거 - SimpleLogin.jsx: AuthContext 직접 사용으로 변경 - 사용자 상태 동기화 문제 완전 해결
This commit is contained in:
66
backend/exports/PR-20251014-003.json
Normal file
66
backend/exports/PR-20251014-003.json
Normal file
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"request_no": "PR-20251014-003",
|
||||
"job_no": "테스트용",
|
||||
"created_at": "2025-10-14T21:40:12.581699",
|
||||
"materials": [
|
||||
{
|
||||
"material_id": 1,
|
||||
"description": "HALF NIPPLE, SMLS, SCH 80S, ASTM A312 TP304 SW X NPT",
|
||||
"category": "FITTING",
|
||||
"size": "1/2\"",
|
||||
"material_grade": "ASTM A312 TP304",
|
||||
"quantity": 3,
|
||||
"unit": "EA",
|
||||
"user_requirement": ""
|
||||
},
|
||||
{
|
||||
"material_id": 3,
|
||||
"description": "HALF NIPPLE, SMLS, SCH 80S, ASTM A312 TP304 SW X NPT",
|
||||
"category": "FITTING",
|
||||
"size": "1/2\"",
|
||||
"material_grade": "ASTM A312 TP304",
|
||||
"quantity": 3,
|
||||
"unit": "EA",
|
||||
"user_requirement": ""
|
||||
},
|
||||
{
|
||||
"material_id": 143,
|
||||
"description": "HALF NIPPLE, SMLS, SCH 160, ASTM A106 B SW * NPT",
|
||||
"category": "FITTING",
|
||||
"size": "1\"",
|
||||
"material_grade": "ASTM A106 B",
|
||||
"quantity": 2,
|
||||
"unit": "EA",
|
||||
"user_requirement": ""
|
||||
}
|
||||
],
|
||||
"grouped_materials": [
|
||||
{
|
||||
"group_key": "HALF NIPPLE, SMLS, SCH 80S, ASTM A312 TP304 SW X NPT|1/2\"|undefined|ASTM A312 TP304",
|
||||
"material_ids": [
|
||||
1,
|
||||
3
|
||||
],
|
||||
"description": "HALF NIPPLE, SMLS, SCH 80S, ASTM A312 TP304 SW X NPT",
|
||||
"category": "FITTING",
|
||||
"size": "1/2\"",
|
||||
"material_grade": "ASTM A312 TP304",
|
||||
"quantity": 3,
|
||||
"unit": "EA",
|
||||
"user_requirement": ""
|
||||
},
|
||||
{
|
||||
"group_key": "HALF NIPPLE, SMLS, SCH 160, ASTM A106 B SW * NPT|1\"|undefined|ASTM A106 B",
|
||||
"material_ids": [
|
||||
143
|
||||
],
|
||||
"description": "HALF NIPPLE, SMLS, SCH 160, ASTM A106 B SW * NPT",
|
||||
"category": "FITTING",
|
||||
"size": "1\"",
|
||||
"material_grade": "ASTM A106 B",
|
||||
"quantity": 2,
|
||||
"unit": "EA",
|
||||
"user_requirement": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
backend/exports/PR-20251014-003.xlsx
Normal file
BIN
backend/exports/PR-20251014-003.xlsx
Normal file
Binary file not shown.
576
backend/exports/PR-20251014-004.json
Normal file
576
backend/exports/PR-20251014-004.json
Normal file
@@ -0,0 +1,576 @@
|
||||
{
|
||||
"request_no": "PR-20251014-004",
|
||||
"job_no": "테스트용",
|
||||
"created_at": "2025-10-14T21:44:18.401404",
|
||||
"materials": [
|
||||
{
|
||||
"material_id": 4,
|
||||
"description": "PIPE, SMLS, SCH 40S, ASTM A312 TP304",
|
||||
"category": "PIPE",
|
||||
"size": "1/2\"",
|
||||
"material_grade": "ASTM A312 TP304",
|
||||
"quantity": 11,
|
||||
"unit": "EA",
|
||||
"user_requirement": ""
|
||||
},
|
||||
{
|
||||
"material_id": 12,
|
||||
"description": "PIPE, SMLS, SCH 80, ASTM A106 B",
|
||||
"category": "PIPE",
|
||||
"size": "3/4\"",
|
||||
"material_grade": "ASTM A106 B",
|
||||
"quantity": 92,
|
||||
"unit": "EA",
|
||||
"user_requirement": ""
|
||||
}
|
||||
],
|
||||
"grouped_materials": [
|
||||
{
|
||||
"group_key": "PIPE, SMLS, SCH 40S, ASTM A312 TP304|1/2\"|undefined|ASTM A312 TP304",
|
||||
"material_ids": [
|
||||
4
|
||||
],
|
||||
"description": "PIPE, SMLS, SCH 40S, ASTM A312 TP304",
|
||||
"category": "PIPE",
|
||||
"size": "1/2\"",
|
||||
"material_grade": "ASTM A312 TP304",
|
||||
"quantity": 11,
|
||||
"unit": "m",
|
||||
"total_length": 1395.1,
|
||||
"pipe_lengths": [
|
||||
{
|
||||
"length": 70,
|
||||
"quantity": 1,
|
||||
"totalLength": 70
|
||||
},
|
||||
{
|
||||
"length": 70,
|
||||
"quantity": 1,
|
||||
"totalLength": 70
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 155,
|
||||
"quantity": 1,
|
||||
"totalLength": 155
|
||||
},
|
||||
{
|
||||
"length": 155,
|
||||
"quantity": 1,
|
||||
"totalLength": 155
|
||||
},
|
||||
{
|
||||
"length": 200,
|
||||
"quantity": 1,
|
||||
"totalLength": 200
|
||||
},
|
||||
{
|
||||
"length": 245.1,
|
||||
"quantity": 1,
|
||||
"totalLength": 245.1
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
}
|
||||
],
|
||||
"user_requirement": ""
|
||||
},
|
||||
{
|
||||
"group_key": "PIPE, SMLS, SCH 80, ASTM A106 B|3/4\"|undefined|ASTM A106 B",
|
||||
"material_ids": [
|
||||
12
|
||||
],
|
||||
"description": "PIPE, SMLS, SCH 80, ASTM A106 B",
|
||||
"category": "PIPE",
|
||||
"size": "3/4\"",
|
||||
"material_grade": "ASTM A106 B",
|
||||
"quantity": 92,
|
||||
"unit": "m",
|
||||
"total_length": 7920.2,
|
||||
"pipe_lengths": [
|
||||
{
|
||||
"length": 60,
|
||||
"quantity": 1,
|
||||
"totalLength": 60
|
||||
},
|
||||
{
|
||||
"length": 60,
|
||||
"quantity": 1,
|
||||
"totalLength": 60
|
||||
},
|
||||
{
|
||||
"length": 60,
|
||||
"quantity": 1,
|
||||
"totalLength": 60
|
||||
},
|
||||
{
|
||||
"length": 60,
|
||||
"quantity": 1,
|
||||
"totalLength": 60
|
||||
},
|
||||
{
|
||||
"length": 43.3,
|
||||
"quantity": 1,
|
||||
"totalLength": 43.3
|
||||
},
|
||||
{
|
||||
"length": 43.3,
|
||||
"quantity": 1,
|
||||
"totalLength": 43.3
|
||||
},
|
||||
{
|
||||
"length": 43.3,
|
||||
"quantity": 1,
|
||||
"totalLength": 43.3
|
||||
},
|
||||
{
|
||||
"length": 43.3,
|
||||
"quantity": 1,
|
||||
"totalLength": 43.3
|
||||
},
|
||||
{
|
||||
"length": 43.3,
|
||||
"quantity": 1,
|
||||
"totalLength": 43.3
|
||||
},
|
||||
{
|
||||
"length": 43.3,
|
||||
"quantity": 1,
|
||||
"totalLength": 43.3
|
||||
},
|
||||
{
|
||||
"length": 50,
|
||||
"quantity": 1,
|
||||
"totalLength": 50
|
||||
},
|
||||
{
|
||||
"length": 50,
|
||||
"quantity": 1,
|
||||
"totalLength": 50
|
||||
},
|
||||
{
|
||||
"length": 50,
|
||||
"quantity": 1,
|
||||
"totalLength": 50
|
||||
},
|
||||
{
|
||||
"length": 50,
|
||||
"quantity": 1,
|
||||
"totalLength": 50
|
||||
},
|
||||
{
|
||||
"length": 50,
|
||||
"quantity": 1,
|
||||
"totalLength": 50
|
||||
},
|
||||
{
|
||||
"length": 50,
|
||||
"quantity": 1,
|
||||
"totalLength": 50
|
||||
},
|
||||
{
|
||||
"length": 50,
|
||||
"quantity": 1,
|
||||
"totalLength": 50
|
||||
},
|
||||
{
|
||||
"length": 70,
|
||||
"quantity": 1,
|
||||
"totalLength": 70
|
||||
},
|
||||
{
|
||||
"length": 70,
|
||||
"quantity": 1,
|
||||
"totalLength": 70
|
||||
},
|
||||
{
|
||||
"length": 70,
|
||||
"quantity": 1,
|
||||
"totalLength": 70
|
||||
},
|
||||
{
|
||||
"length": 70,
|
||||
"quantity": 1,
|
||||
"totalLength": 70
|
||||
},
|
||||
{
|
||||
"length": 70,
|
||||
"quantity": 1,
|
||||
"totalLength": 70
|
||||
},
|
||||
{
|
||||
"length": 70,
|
||||
"quantity": 1,
|
||||
"totalLength": 70
|
||||
},
|
||||
{
|
||||
"length": 70,
|
||||
"quantity": 1,
|
||||
"totalLength": 70
|
||||
},
|
||||
{
|
||||
"length": 70,
|
||||
"quantity": 1,
|
||||
"totalLength": 70
|
||||
},
|
||||
{
|
||||
"length": 70,
|
||||
"quantity": 1,
|
||||
"totalLength": 70
|
||||
},
|
||||
{
|
||||
"length": 70,
|
||||
"quantity": 1,
|
||||
"totalLength": 70
|
||||
},
|
||||
{
|
||||
"length": 70,
|
||||
"quantity": 1,
|
||||
"totalLength": 70
|
||||
},
|
||||
{
|
||||
"length": 70,
|
||||
"quantity": 1,
|
||||
"totalLength": 70
|
||||
},
|
||||
{
|
||||
"length": 76.2,
|
||||
"quantity": 1,
|
||||
"totalLength": 76.2
|
||||
},
|
||||
{
|
||||
"length": 76.2,
|
||||
"quantity": 1,
|
||||
"totalLength": 76.2
|
||||
},
|
||||
{
|
||||
"length": 76.2,
|
||||
"quantity": 1,
|
||||
"totalLength": 76.2
|
||||
},
|
||||
{
|
||||
"length": 76.2,
|
||||
"quantity": 1,
|
||||
"totalLength": 76.2
|
||||
},
|
||||
{
|
||||
"length": 76.2,
|
||||
"quantity": 1,
|
||||
"totalLength": 76.2
|
||||
},
|
||||
{
|
||||
"length": 76.2,
|
||||
"quantity": 1,
|
||||
"totalLength": 76.2
|
||||
},
|
||||
{
|
||||
"length": 77.6,
|
||||
"quantity": 1,
|
||||
"totalLength": 77.6
|
||||
},
|
||||
{
|
||||
"length": 77.6,
|
||||
"quantity": 1,
|
||||
"totalLength": 77.6
|
||||
},
|
||||
{
|
||||
"length": 77.6,
|
||||
"quantity": 1,
|
||||
"totalLength": 77.6
|
||||
},
|
||||
{
|
||||
"length": 77.6,
|
||||
"quantity": 1,
|
||||
"totalLength": 77.6
|
||||
},
|
||||
{
|
||||
"length": 77.6,
|
||||
"quantity": 1,
|
||||
"totalLength": 77.6
|
||||
},
|
||||
{
|
||||
"length": 77.6,
|
||||
"quantity": 1,
|
||||
"totalLength": 77.6
|
||||
},
|
||||
{
|
||||
"length": 80,
|
||||
"quantity": 1,
|
||||
"totalLength": 80
|
||||
},
|
||||
{
|
||||
"length": 80,
|
||||
"quantity": 1,
|
||||
"totalLength": 80
|
||||
},
|
||||
{
|
||||
"length": 80,
|
||||
"quantity": 1,
|
||||
"totalLength": 80
|
||||
},
|
||||
{
|
||||
"length": 80,
|
||||
"quantity": 1,
|
||||
"totalLength": 80
|
||||
},
|
||||
{
|
||||
"length": 80,
|
||||
"quantity": 1,
|
||||
"totalLength": 80
|
||||
},
|
||||
{
|
||||
"length": 80,
|
||||
"quantity": 1,
|
||||
"totalLength": 80
|
||||
},
|
||||
{
|
||||
"length": 80,
|
||||
"quantity": 1,
|
||||
"totalLength": 80
|
||||
},
|
||||
{
|
||||
"length": 80,
|
||||
"quantity": 1,
|
||||
"totalLength": 80
|
||||
},
|
||||
{
|
||||
"length": 80,
|
||||
"quantity": 1,
|
||||
"totalLength": 80
|
||||
},
|
||||
{
|
||||
"length": 88.6,
|
||||
"quantity": 1,
|
||||
"totalLength": 88.6
|
||||
},
|
||||
{
|
||||
"length": 88.6,
|
||||
"quantity": 1,
|
||||
"totalLength": 88.6
|
||||
},
|
||||
{
|
||||
"length": 98.4,
|
||||
"quantity": 1,
|
||||
"totalLength": 98.4
|
||||
},
|
||||
{
|
||||
"length": 98.4,
|
||||
"quantity": 1,
|
||||
"totalLength": 98.4
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 100,
|
||||
"quantity": 1,
|
||||
"totalLength": 100
|
||||
},
|
||||
{
|
||||
"length": 120,
|
||||
"quantity": 1,
|
||||
"totalLength": 120
|
||||
},
|
||||
{
|
||||
"length": 120,
|
||||
"quantity": 1,
|
||||
"totalLength": 120
|
||||
},
|
||||
{
|
||||
"length": 150,
|
||||
"quantity": 1,
|
||||
"totalLength": 150
|
||||
},
|
||||
{
|
||||
"length": 150,
|
||||
"quantity": 1,
|
||||
"totalLength": 150
|
||||
},
|
||||
{
|
||||
"length": 150,
|
||||
"quantity": 1,
|
||||
"totalLength": 150
|
||||
},
|
||||
{
|
||||
"length": 150,
|
||||
"quantity": 1,
|
||||
"totalLength": 150
|
||||
},
|
||||
{
|
||||
"length": 150,
|
||||
"quantity": 1,
|
||||
"totalLength": 150
|
||||
},
|
||||
{
|
||||
"length": 223.6,
|
||||
"quantity": 1,
|
||||
"totalLength": 223.6
|
||||
}
|
||||
],
|
||||
"user_requirement": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
backend/exports/PR-20251014-004.xlsx
Normal file
BIN
backend/exports/PR-20251014-004.xlsx
Normal file
Binary file not shown.
@@ -13,15 +13,14 @@ import PurchaseRequestPage from './pages/PurchaseRequestPage';
|
||||
import SystemLogsPage from './pages/SystemLogsPage';
|
||||
import LogMonitoringPage from './pages/LogMonitoringPage';
|
||||
import InactiveProjectsPage from './pages/InactiveProjectsPage';
|
||||
import { AuthProvider, useAuth } from './contexts/AuthContext';
|
||||
import errorLogger from './utils/errorLogger';
|
||||
import api from './api';
|
||||
import './App.css';
|
||||
|
||||
function App() {
|
||||
function AppContent() {
|
||||
// TK-MP BOM Management System v2.0 - Project Selection Dashboard
|
||||
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [user, setUser] = useState(null);
|
||||
const { user, isAuthenticated, isLoading, logout } = useAuth();
|
||||
const [currentPage, setCurrentPage] = useState('dashboard');
|
||||
const [pageParams, setPageParams] = useState({});
|
||||
const [selectedProject, setSelectedProject] = useState(null);
|
||||
@@ -177,30 +176,13 @@ function App() {
|
||||
});
|
||||
};
|
||||
|
||||
// 인증 상태 확인
|
||||
// 인증된 사용자의 데이터 로드
|
||||
useEffect(() => {
|
||||
const checkAuth = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('access_token');
|
||||
if (token) {
|
||||
api.defaults.headers.common['Authorization'] = `Bearer ${token}`;
|
||||
const userResponse = await api.get('/auth/me');
|
||||
setUser(userResponse.data.user);
|
||||
setIsAuthenticated(true);
|
||||
await loadPendingSignups();
|
||||
await loadProjects(); // 프로젝트 로드 추가
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('인증 확인 실패:', error);
|
||||
localStorage.removeItem('access_token');
|
||||
localStorage.removeItem('user_data');
|
||||
setIsAuthenticated(false);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
checkAuth();
|
||||
}, []);
|
||||
if (isAuthenticated && user) {
|
||||
loadPendingSignups();
|
||||
loadProjects();
|
||||
}
|
||||
}, [isAuthenticated, user]);
|
||||
|
||||
// 페이지 이동 함수
|
||||
const navigateToPage = (page, params = {}) => {
|
||||
@@ -359,22 +341,11 @@ function App() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleLogout = () => {
|
||||
localStorage.removeItem('access_token');
|
||||
localStorage.removeItem('user_data');
|
||||
setIsAuthenticated(false);
|
||||
setUser(null);
|
||||
const handleLogout = async () => {
|
||||
await logout();
|
||||
setCurrentPage('dashboard');
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
const handleLoginSuccess = (userData) => {
|
||||
setIsAuthenticated(true);
|
||||
setUser(userData);
|
||||
setIsLoading(false);
|
||||
loadPendingSignups();
|
||||
loadProjects();
|
||||
};
|
||||
|
||||
return (
|
||||
<ErrorBoundary errorContext={{ user, currentPage, pageParams }}>
|
||||
@@ -392,7 +363,7 @@ function App() {
|
||||
</div>
|
||||
</div>
|
||||
) : !isAuthenticated ? (
|
||||
<SimpleLogin onLoginSuccess={handleLoginSuccess} />
|
||||
<SimpleLogin />
|
||||
) : (
|
||||
<div style={{ minHeight: '100vh', background: '#f7fafc' }}>
|
||||
{/* 상단 헤더 */}
|
||||
@@ -429,4 +400,13 @@ function App() {
|
||||
);
|
||||
}
|
||||
|
||||
// AuthProvider로 감싸는 래퍼 컴포넌트
|
||||
function App() {
|
||||
return (
|
||||
<AuthProvider>
|
||||
<AppContent />
|
||||
</AuthProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
@@ -1,7 +1,9 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useAuth } from './contexts/AuthContext';
|
||||
import api from './api';
|
||||
|
||||
const SimpleLogin = ({ onLoginSuccess }) => {
|
||||
const SimpleLogin = () => {
|
||||
const { login } = useAuth();
|
||||
const [formData, setFormData] = useState({
|
||||
username: '',
|
||||
password: ''
|
||||
@@ -110,28 +112,11 @@ const SimpleLogin = ({ onLoginSuccess }) => {
|
||||
setError('');
|
||||
|
||||
try {
|
||||
const response = await api.post('/auth/login', formData);
|
||||
const data = response.data;
|
||||
|
||||
if (data.success) {
|
||||
// 토큰과 사용자 정보 저장
|
||||
localStorage.setItem('access_token', data.access_token);
|
||||
localStorage.setItem('user_data', JSON.stringify(data.user));
|
||||
|
||||
setSuccess('로그인 성공! 대시보드로 이동합니다...');
|
||||
|
||||
// 잠깐 성공 메시지 보여준 후 대시보드로 이동
|
||||
setTimeout(() => {
|
||||
if (onLoginSuccess) {
|
||||
onLoginSuccess();
|
||||
}
|
||||
}, 1000);
|
||||
} else {
|
||||
setError(data.error?.message || '로그인에 실패했습니다.');
|
||||
}
|
||||
await login(formData.username, formData.password);
|
||||
setSuccess('로그인 성공! 대시보드로 이동합니다...');
|
||||
} catch (err) {
|
||||
console.error('Login error:', err);
|
||||
setError(err.response?.data?.message || '서버 연결에 실패했습니다.');
|
||||
setError(err.message || '서버 연결에 실패했습니다.');
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user