Files
M-Project/frontend/static/js/auth-common.js
hyungi 41b557a709 Fix: 페이지 간 이동 시 로그아웃 문제 해결 및 기능 개선
- 토큰 저장 키 통일 (access_token으로 일관성 확보)
- 일일공수 페이지 API 스크립트 로딩 순서 수정
- 프로젝트 관리 페이지 비활성 프로젝트 표시 문제 해결
- 업로드 카테고리에 '기타' 항목 추가 (백엔드 schemas.py 포함)
- 비밀번호 변경 기능 API 연동으로 수정
- 프로젝트 드롭다운 z-index 문제 해결
- CORS 설정 및 Nginx 구성 개선
- 비밀번호 해싱 방식 pbkdf2_sha256으로 변경 (bcrypt 72바이트 제한 해결)
2025-10-25 07:22:20 +09:00

82 lines
2.4 KiB
JavaScript

// 공통 인증 및 네비게이션 관리
class AuthCommon {
static init(currentPage = '') {
// 토큰 기반 사용자 정보 확인
const user = TokenManager.getUser();
if (!user) {
window.location.href = 'index.html';
return null;
}
// 전역 currentUser 설정
window.currentUser = user;
// 헤더 생성 (페이지별로 다른 active 상태)
CommonHeader.init(currentPage);
// 사용자 정보 표시
this.updateUserDisplay(user);
// 네비게이션 권한 업데이트
this.updateNavigation(user);
return user;
}
static updateUserDisplay(user) {
const userDisplayElement = document.getElementById('userDisplay');
if (userDisplayElement) {
const displayName = user.full_name || user.username;
userDisplayElement.textContent = `${displayName} (${user.username})`;
}
}
static updateNavigation(user) {
const isAdmin = user.role === 'admin';
// 관리자 전용 메뉴들
const adminMenus = [
'dailyWorkBtn',
'listBtn',
'summaryBtn',
'projectBtn'
];
adminMenus.forEach(menuId => {
const element = document.getElementById(menuId);
if (element) {
element.style.display = isAdmin ? '' : 'none';
}
});
// 관리자 버튼 처리 (드롭다운 vs 단순 버튼)
const adminBtnContainer = document.getElementById('adminBtnContainer');
const userPasswordBtn = document.getElementById('userPasswordBtn');
if (isAdmin) {
// 관리자: 드롭다운 메뉴 표시
if (adminBtnContainer) adminBtnContainer.style.display = '';
if (userPasswordBtn) userPasswordBtn.style.display = 'none';
} else {
// 일반 사용자: 비밀번호 변경 버튼만 표시
if (adminBtnContainer) adminBtnContainer.style.display = 'none';
if (userPasswordBtn) userPasswordBtn.style.display = '';
}
}
static logout() {
AuthAPI.logout();
}
}
// 전역 함수들
function logout() {
AuthCommon.logout();
}
function showSection(sectionName) {
if (typeof window.showSection === 'function') {
window.showSection(sectionName);
}
}