feat(auth): 新增站点登录(nginx auth_request + scrypt 密码 + 签名 Cookie),登录页与退出入口,API 路径保持 Key 鉴权

This commit is contained in:
sgp
2026-11-04 18:43:00 +08:00
parent ca75da8589
commit 28af756b82
6 changed files with 590 additions and 7 deletions
+13
View File
@@ -27,6 +27,7 @@
<i class="api-dot"></i><span class="api-text">API</span>
</span>
<a class="hub-btn primary" href="index.html" data-nav>进入设计工作台 <span aria-hidden="true">→</span></a>
<button class="hub-btn" id="btn-logout" title="退出登录">退出</button>
</div>
</header>
@@ -337,6 +338,18 @@
// 本地静态预览没有 /api/ 服务,直接跳过探测,避免控制台出现 ERR_ABORTED
var IS_LOCAL = /^(localhost|127\.0\.0\.1|\[::1\])$/.test(location.hostname);
var API_BASE = IS_LOCAL ? 'http://127.0.0.1:7891' : '';
// 退出登录
var logoutBtn = $('#btn-logout');
if (logoutBtn) {
logoutBtn.addEventListener('click', function () {
logoutBtn.disabled = true;
fetch(API_BASE + '/api/v1/auth/logout', { method: 'POST', credentials: 'include' })
.catch(function () { /* 忽略 */ })
.then(function () { location.href = 'login.html'; });
});
}
if (IS_LOCAL) {
setApi('idle', '本地');