import { html } from 'lit'; import { LightElement } from '../lib/base.js'; export class SetupPage extends LightElement { static get properties() { return { _username: { state: true }, _password: { state: true }, _confirm: { state: true }, _encrypted: { state: true }, _error: { state: true }, _busy: { state: true }, }; } constructor() { super(); this._username = ''; this._password = ''; this._confirm = ''; this._encrypted = true; this._error = null; this._busy = false; } _submit(e) { e.preventDefault(); if (this._busy) return; this._error = null; if (!this._username.trim()) { this._error = 'Choose a username.'; return; } if (this._password.length < 4) { this._error = 'Password must be at least 4 characters.'; return; } if (this._password !== this._confirm) { this._error = 'The two passwords do not match.'; return; } this._doCreate(); } async _doCreate() { this._busy = true; try { const res = await fetch('/api/setup/user', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username: this._username.trim(), password: this._password, encrypted: this._encrypted, }), }); if (!res.ok) { const txt = await res.text(); this._error = txt || `Request failed (${res.status}).`; return; } // First user created — reload into the app. window.location.reload(); } catch { this._error = 'Network error — please try again.'; } finally { this._busy = false; } } render() { const btnLabel = this._busy ? html`Creating…` : 'Create account'; return html`

Welcome to Skald

Create the admin account to get started.

${this._error ? html`
${this._error}
` : null}
this._username = e.target.value} ?disabled=${this._busy} required />
this._password = e.target.value} ?disabled=${this._busy} required />
this._confirm = e.target.value} ?disabled=${this._busy} required />
this._encrypted = e.target.checked} ?disabled=${this._busy} />
${this._encrypted ? html`
Warning: your password derives the encryption key. If you forget it, your entire conversation history will be permanently lost — there is no recovery.
` : null}
`; } }