회원 불러오기 작업하는 중1

This commit is contained in:
2025-11-26 21:40:56 +09:00
parent 47eedf6837
commit 53a5713ddd
12 changed files with 494 additions and 809 deletions

View File

@@ -39,7 +39,11 @@ export default function LoginPage() {
if (savedToken && cookieToken && savedToken === cookieToken) {
// 토큰이 유효한지 확인
fetch('https://hrdi.coconutmeet.net/auth/me', {
const apiUrl = process.env.NEXT_PUBLIC_API_BASE_URL
? `${process.env.NEXT_PUBLIC_API_BASE_URL}/auth/me`
: 'https://hrdi.coconutmeet.net/auth/me';
fetch(apiUrl, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
@@ -48,10 +52,28 @@ export default function LoginPage() {
})
.then(response => {
if (response.ok) {
// 토큰이 유효하면 메인 페이지로 리다이렉트
const searchParams = new URLSearchParams(window.location.search);
const redirectPath = searchParams.get('redirect') || '/';
router.push(redirectPath);
return response.json().then(userData => {
// 계정 상태 확인
const userStatus = userData.status || userData.userStatus;
if (userStatus === 'INACTIVE' || userStatus === 'inactive') {
// 비활성화된 계정인 경우 로그아웃 처리
localStorage.removeItem('token');
document.cookie = 'token=; path=/; max-age=0';
return;
}
// 사용자 권한 확인
const userRole = userData.role || userData.userRole;
if (userRole === 'ADMIN' || userRole === 'admin') {
// admin 권한이면 /admin/id로 리다이렉트
router.push('/admin/id');
} else {
// 그 외의 경우 기존 로직대로 리다이렉트
const searchParams = new URLSearchParams(window.location.search);
const redirectPath = searchParams.get('redirect') || '/';
router.push(redirectPath);
}
});
} else {
// 토큰이 유효하지 않으면 삭제
localStorage.removeItem('token');
@@ -150,6 +172,30 @@ export default function LoginPage() {
// 토큰이 없어도 로그인은 성공했으므로 진행
}
// 사용자 정보 가져오기 (권한 확인을 위해)
try {
const userResponse = await fetch('https://hrdi.coconutmeet.net/auth/me', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
});
if (userResponse.ok) {
const userData = await userResponse.json();
const userRole = userData.role || userData.userRole;
// admin 권한이면 /admin/id로 리다이렉트
if (userRole === 'ADMIN' || userRole === 'admin') {
router.push('/admin/id');
return;
}
}
} catch (error) {
console.error("사용자 정보 조회 오류:", error);
// 사용자 정보 조회 실패 시에도 기존 로직대로 진행
}
// 리다이렉트 경로 확인
const searchParams = new URLSearchParams(window.location.search);