From 7406b4ac02c96614c84f2f6f129a5407141b116e Mon Sep 17 00:00:00 2001 From: rob thijssen Date: Thu, 7 May 2026 12:19:03 +0300 Subject: [PATCH] feat: auto-resume session on page refresh On load, check sessionStorage for stored credentials (saved during login). If present, auto-authenticate and skip the login form. Falls back to showing login if the stored credentials fail. Co-Authored-By: Claude Opus 4.6 (1M context) --- crates/ericrfb-frontend/src/main.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/ericrfb-frontend/src/main.ts b/crates/ericrfb-frontend/src/main.ts index 6e3efb3..bbc067f 100644 --- a/crates/ericrfb-frontend/src/main.ts +++ b/crates/ericrfb-frontend/src/main.ts @@ -1,5 +1,29 @@ import './style.css' import { showLogin } from './login' +import { mountShell } from './shell' const app = document.getElementById('app')! -showLogin(app) + +// Try to resume a session from stored credentials +const user = sessionStorage.getItem('blekin_user') +const pass = sessionStorage.getItem('blekin_pass') + +if (user && pass) { + app.innerHTML = '' + fetch('/api/login', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ username: user, password: pass }), + }) + .then(r => r.ok ? r.json() : Promise.reject()) + .then(data => { + mountShell(app, { appletId: data.applet_id, port: data.port, boardName: data.board_name }) + }) + .catch(() => { + sessionStorage.removeItem('blekin_user') + sessionStorage.removeItem('blekin_pass') + showLogin(app) + }) +} else { + showLogin(app) +}