Files
lunarfront-manager/frontend/index.html
Ryan Moon 4bd1918e3b
Some checks failed
Build & Release / build (push) Has been cancelled
feat: add JWT auth with db-backed users
- users table created on startup via migrate()
- POST /api/auth/setup to create first user (blocked once any user exists)
- POST /api/auth/login returns httpOnly JWT cookie (7d expiry)
- POST /api/auth/logout clears cookie
- GET /api/auth/me for auth check
- All /api/customers routes require valid JWT
- Frontend shows login form when unauthenticated
- Fix type errors in k8s, do, and pgbouncer services
2026-04-03 07:41:36 -05:00

133 lines
5.3 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LunarFront Manager</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, sans-serif; background: #0f0f0f; color: #e0e0e0; min-height: 100vh; padding: 2rem; }
h1 { font-size: 1.5rem; margin-bottom: 2rem; color: #fff; }
.card { background: #1a1a1a; border: 1px solid #2a2a2a; border-radius: 8px; padding: 1.5rem; max-width: 480px; }
h2 { font-size: 1rem; margin-bottom: 1rem; color: #aaa; text-transform: uppercase; letter-spacing: 0.05em; }
label { display: block; font-size: 0.85rem; color: #aaa; margin-bottom: 0.4rem; }
input { width: 100%; padding: 0.6rem 0.8rem; background: #111; border: 1px solid #333; border-radius: 6px; color: #fff; font-size: 0.95rem; margin-bottom: 1rem; }
input:focus { outline: none; border-color: #555; }
button { padding: 0.6rem 1.2rem; background: #2563eb; border: none; border-radius: 6px; color: #fff; font-size: 0.95rem; cursor: pointer; }
button:hover { background: #1d4ed8; }
button:disabled { background: #333; cursor: not-allowed; }
.status { margin-top: 1rem; font-size: 0.85rem; padding: 0.6rem 0.8rem; border-radius: 6px; display: none; }
.status.success { background: #14532d; color: #86efac; display: block; }
.status.error { background: #450a0a; color: #fca5a5; display: block; }
.header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 2rem; }
.logout-btn { background: none; border: 1px solid #333; color: #aaa; font-size: 0.8rem; padding: 0.4rem 0.8rem; }
.logout-btn:hover { background: #1a1a1a; color: #fff; }
#login-view, #app-view { display: none; }
</style>
</head>
<body>
<div id="login-view">
<h1>LunarFront Manager</h1>
<div class="card">
<h2>Sign In</h2>
<label for="login-username">Username</label>
<input id="login-username" type="text" autocomplete="username" />
<label for="login-password">Password</label>
<input id="login-password" type="password" autocomplete="current-password" onkeydown="if(event.key==='Enter')login()" />
<button onclick="login()">Sign In</button>
<div id="login-status" class="status"></div>
</div>
</div>
<div id="app-view">
<div class="header">
<h1>LunarFront Manager</h1>
<button class="logout-btn" onclick="logout()">Sign Out</button>
</div>
<div class="card">
<h2>Provision Customer</h2>
<label for="name">Customer Slug</label>
<input id="name" type="text" placeholder="acme-shop" pattern="[a-z0-9-]+" />
<button id="provision-btn" onclick="provision()">Provision</button>
<div id="provision-status" class="status"></div>
</div>
</div>
<script>
async function checkAuth() {
const res = await fetch('/api/auth/me');
if (res.ok) {
document.getElementById('app-view').style.display = 'block';
} else {
document.getElementById('login-view').style.display = 'block';
}
}
async function login() {
const username = document.getElementById('login-username').value.trim();
const password = document.getElementById('login-password').value;
const status = document.getElementById('login-status');
status.className = 'status';
try {
const res = await fetch('/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password }),
});
const data = await res.json();
if (!res.ok) throw new Error(data.message ?? 'Login failed');
document.getElementById('login-view').style.display = 'none';
document.getElementById('app-view').style.display = 'block';
} catch (err) {
status.textContent = err.message;
status.className = 'status error';
}
}
async function logout() {
await fetch('/api/auth/logout', { method: 'POST' });
document.getElementById('app-view').style.display = 'none';
document.getElementById('login-view').style.display = 'block';
document.getElementById('login-password').value = '';
}
async function provision() {
const name = document.getElementById('name').value.trim();
const btn = document.getElementById('provision-btn');
const status = document.getElementById('provision-status');
if (!name) return;
btn.disabled = true;
btn.textContent = 'Provisioning...';
status.className = 'status';
try {
const res = await fetch('/api/customers', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name }),
});
const data = await res.json();
if (!res.ok) throw new Error(data.message ?? 'Unknown error');
status.textContent = `${data.slug} provisioned successfully`;
status.className = 'status success';
document.getElementById('name').value = '';
} catch (err) {
status.textContent = `${err.message}`;
status.className = 'status error';
} finally {
btn.disabled = false;
btn.textContent = 'Provision';
}
}
checkAuth();
</script>
</body>
</html>