happy path working with stub companion app

This commit is contained in:
2026-08-18 02:16:05 +02:00
parent 3c11a88a33
commit bc025d007c
41 changed files with 1512 additions and 102 deletions
+45 -3
View File
@@ -24,6 +24,7 @@
<input id="username" type="text" placeholder="Username" readonly />
<input id="password" type="password" placeholder="Password" readonly />
<button id="sign-in-btn" type="button" disabled>Sign in with LOCQR</button>
<button id="log-out-btn" type="button" style="display: none;">Log out (this site only)</button>
</form>
<h2 style="font-size: 14px;">Event log</h2>
@@ -51,6 +52,19 @@
// in development"). Stable as long as key.pem doesn't change.
const DEV_EXTENSION_ID = 'daijigbjegngkjckedcbhhdjkampjgia';
// Stands in for this site's own real session mechanism (a cookie, a
// server-checked session — whatever it already uses). LOCQR has no
// opinion on this and doesn't provide it; reportSession() just needs
// *something* to report, and localStorage is the simplest thing that
// survives a refresh for demo purposes.
const SESSION_KEY = 'locqr-test-session';
const hasSimulatedSession = () => localStorage.getItem(SESSION_KEY) === 'active';
const setSimulatedSession = (active) => {
if (active) localStorage.setItem(SESSION_KEY, 'active');
else localStorage.removeItem(SESSION_KEY);
logOutBtn.style.display = active ? '' : 'none';
};
async function main() {
log('page:loaded');
@@ -74,7 +88,20 @@
locqr.on('ready', (payload) => log('event:ready', payload));
locqr.on('run:started', (payload) => log('event:run:started', payload));
locqr.on('run:delivered', (payload) => log('event:run:delivered', payload));
locqr.on('run:delivered', (payload) => {
log('event:run:delivered', payload);
// Fills the form here too, not just inside the Sign-in button's own
// requestCredential() promise — this event fires for a credential
// delivered from *any* trigger (e.g. the extension popup's own
// Sign in button), and the form should reflect that regardless of
// which side started the run (sdk/claude.md: "sites using the
// event model do not need to call requestCredential()").
usernameEl.value = payload.credential.username;
passwordEl.value = payload.credential.password;
setSimulatedSession(true);
locqr.reportSession({ active: true });
log('reportSession', { active: true });
});
locqr.on('run:error', (payload) => log('event:run:error', payload));
locqr.init({ cert, extensionId: DEV_EXTENSION_ID });
@@ -84,6 +111,11 @@
statusEl.textContent = `Ready — features: ${result.features.join(', ')}`;
log('ready:resolved', result);
signInBtn.disabled = false;
const active = hasSimulatedSession();
logOutBtn.style.display = active ? '' : 'none';
locqr.reportSession({ active });
log('reportSession', { active });
} catch (error) {
statusEl.textContent = `Not ready — ${error.code}${error.reason ? ' / ' + error.reason : ''}`;
log('ready:rejected', error);
@@ -91,18 +123,28 @@
}
const signInBtn = document.getElementById('sign-in-btn');
const logOutBtn = document.getElementById('log-out-btn');
const usernameEl = document.getElementById('username');
const passwordEl = document.getElementById('password');
logOutBtn.addEventListener('click', () => {
setSimulatedSession(false);
usernameEl.value = '';
passwordEl.value = '';
locqr.reportSession({ active: false });
log('reportSession', { active: false });
});
signInBtn.addEventListener('click', async () => {
signInBtn.disabled = true;
usernameEl.value = '';
passwordEl.value = '';
log('requestCredential:called');
try {
// Field population happens in the run:delivered event listener
// above, not here — that fires for a delivery from any trigger,
// this promise only resolves for one started by this exact click.
const credential = await locqr.requestCredential();
usernameEl.value = credential.username;
passwordEl.value = credential.password;
log('requestCredential:resolved', { username: credential.username });
} catch (error) {
statusEl.textContent = `Sign-in didn't complete — ${error.code}${error.reason ? ' / ' + error.reason : ''}`;