미인증 상태 데이터 호출 차단

This commit is contained in:
seo
2026-07-02 13:18:58 +09:00
parent 7b1abb009a
commit 37fa87921c
+65 -43
View File
@@ -465,6 +465,51 @@ const BACK_LINK_PATH_TITLE = {
'/home': '홈',
'/blog': '블로그',
};
const FINDMYDEVICE_AUTH_REQUIRED = location.pathname.startsWith('/findmydevice');
let findmydeviceAuthenticated = !FINDMYDEVICE_AUTH_REQUIRED;
function renderAuthErrorPage() {
document.body.innerHTML = `
<main class="find-auth-page">
<div id="findMyShortcut"></div>
</main>
`;
const renderPin = () => window.CustomAuthPin?.render({
mount: '#findMyShortcut',
title: '비밀번호',
placeholder: '비밀번호',
backLabel: '채건닷컴',
backHref: 'https://chaegeon.com/',
onSuccess: () => location.reload(),
});
if (window.CustomAuthPin) {
renderPin();
return;
}
const script = document.createElement('script');
script.src = '/custom/common/js/auth-pin.js';
script.onload = renderPin;
document.body.appendChild(script);
}
const findmydeviceAuthPromise = FINDMYDEVICE_AUTH_REQUIRED
? fetch('/custom/launcher/api.php?session=1', { credentials: 'same-origin' })
.then(res => res.ok ? res.json() : Promise.reject())
.then(session => {
findmydeviceAuthenticated = !!session.authenticated;
return findmydeviceAuthenticated;
})
.catch(() => {
findmydeviceAuthenticated = false;
return false;
})
: Promise.resolve(true);
function runAfterFindAuth(callback) {
return findmydeviceAuthPromise
.then(ok => ok ? callback() : null)
.catch(() => null);
}
function cleanPageTitle(title) {
return String(title || '')
@@ -622,7 +667,7 @@ document.getElementById('langToggle').addEventListener('click', () => {
localStorage.setItem('currentLang', langCode);
applyLanguage(langCode);
fetchDeviceData(true).then(data => updateDOMWithData(data));
runAfterFindAuth(() => fetchDeviceData(true).then(data => updateDOMWithData(data)));
// locateBtn 즉시 재렌더링
if (document.getElementById('locateBtn')) {
@@ -680,41 +725,12 @@ document.addEventListener('DOMContentLoaded', () => {
setupBackLink();
function renderAuthErrorPage() {
document.body.innerHTML = `
<main class="find-auth-page">
<div id="findMyShortcut"></div>
</main>
`;
const renderPin = () => window.CustomAuthPin?.render({
mount: '#findMyShortcut',
title: '비밀번호',
placeholder: '비밀번호',
backLabel: '채건닷컴',
backHref: 'https://chaegeon.com/',
onSuccess: () => location.reload(),
if (FINDMYDEVICE_AUTH_REQUIRED) {
findmydeviceAuthPromise.then(ok => {
if (!ok) renderAuthErrorPage();
});
if (window.CustomAuthPin) {
renderPin();
return;
}
const script = document.createElement('script');
script.src = '/custom/common/js/auth-pin.js';
script.onload = renderPin;
document.body.appendChild(script);
}
if (location.pathname.startsWith('/findmydevice')) {
fetch('/custom/launcher/api.php?session=1', { credentials: 'same-origin' })
.then(res => res.ok ? res.json() : Promise.reject())
.then(session => {
if (!session.authenticated) {
renderAuthErrorPage();
}
})
.catch(renderAuthErrorPage);
}
const btnArea = document.querySelector('body > div.btnArea');
const pageModifyLink = btnArea?.querySelectorAll('a')[1]?.getAttribute('href') || '';
if (btnArea) btnArea.remove();
@@ -832,12 +848,12 @@ document.addEventListener('DOMContentLoaded', () => {
// 3) 지도 히스토리 초기화 & 라이브 데이터 재요청 + 현재 위치로 이동
resetHistoryLayer();
fetchDeviceData(true).then(data => {
updateDOMWithData(data);
if (data.latitude && data.longitude && mapState.map) {
mapState.map.panTo(new naver.maps.LatLng(data.latitude, data.longitude));
}
});
runAfterFindAuth(() => fetchDeviceData(true).then(data => {
updateDOMWithData(data);
if (data.latitude && data.longitude && mapState.map) {
mapState.map.panTo(new naver.maps.LatLng(data.latitude, data.longitude));
}
}));
});
}
@@ -917,7 +933,7 @@ document.addEventListener('DOMContentLoaded', () => {
endEl.addEventListener(ev, () => fire(true));
});
fire(false);
runAfterFindAuth(() => fire(false));
})();
});
@@ -970,13 +986,15 @@ document.getElementById('autoUpdateSwitch').addEventListener('change', () => {
});
setInterval(() => {
if (!findmydeviceAuthenticated) return;
if (document.getElementById('autoUpdateSwitch')?.checked) {
callDeviceWebhook('auto_tick');
}
}, 10000);
setInterval(() => {
if (lastUpdateISOTime) {
setInterval(() => {
if (!findmydeviceAuthenticated) return;
if (lastUpdateISOTime) {
const el = document.getElementById("lastUpdateTime");
if (el) el.textContent = getRelativeTime(lastUpdateISOTime);
}
@@ -2398,6 +2416,10 @@ function syncUpdateBtn() {
}
function fetchDeviceData(includeLang = true, range = null) {
if (!findmydeviceAuthenticated) {
return Promise.reject(new Error('not_authenticated'));
}
const params = new URLSearchParams(includeLang ? { lang: langCode } : { hashonly: 1 });
// 우선순위: 직접 인자(range) > 전역 오버라이드(_overrideRange)