fix(admin): include credentials on auth requests and adapt login response
This commit is contained in:
@@ -461,7 +461,7 @@ class AdminFileManager {
|
|||||||
|
|
||||||
async checkSession() {
|
async checkSession() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/auth/session');
|
const response = await fetch('/api/auth/session', { credentials: 'include' });
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (data.user) {
|
if (data.user) {
|
||||||
@@ -494,20 +494,21 @@ class AdminFileManager {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
|
credentials: 'include',
|
||||||
body: JSON.stringify({ email, password })
|
body: JSON.stringify({ email, password })
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
this.currentUser = data.user;
|
this.currentUser = data.user || data.data || null;
|
||||||
this.isLoggedIn = true;
|
this.isLoggedIn = true;
|
||||||
this.showNotification('로그인되었습니다!', 'success');
|
this.showNotification('로그인되었습니다!', 'success');
|
||||||
|
|
||||||
await this.loadData();
|
await this.loadData();
|
||||||
this.updateUI();
|
this.updateUI();
|
||||||
} else {
|
} else {
|
||||||
throw new Error(data.message || '로그인에 실패했습니다.');
|
throw new Error(data.error || data.message || '로그인에 실패했습니다.');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('로그인 오류:', error);
|
console.error('로그인 오류:', error);
|
||||||
@@ -520,7 +521,7 @@ class AdminFileManager {
|
|||||||
|
|
||||||
async handleLogout() {
|
async handleLogout() {
|
||||||
try {
|
try {
|
||||||
await fetch('/api/auth/logout', { method: 'POST' });
|
await fetch('/api/auth/logout', { method: 'POST', credentials: 'include' });
|
||||||
|
|
||||||
this.currentUser = null;
|
this.currentUser = null;
|
||||||
this.isLoggedIn = false;
|
this.isLoggedIn = false;
|
||||||
|
Reference in New Issue
Block a user