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) <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user