feat: auto-resume session on page refresh
All checks were successful
CI / fmt (push) Successful in 35s
Publish / frontend (push) Successful in 48s
CI / check (push) Successful in 1m28s
CI / clippy (push) Successful in 1m25s
Publish / backend (push) Successful in 2m42s

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) <noreply@anthropic.com>
This commit is contained in:
2026-05-07 12:19:03 +03:00
parent 35db634317
commit 7406b4ac02

View File

@@ -1,5 +1,29 @@
import './style.css' import './style.css'
import { showLogin } from './login' import { showLogin } from './login'
import { mountShell } from './shell'
const app = document.getElementById('app')! 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 = '<div class="login"><div class="login-form"><h1>Reconnecting...</h1></div></div>'
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)
}