fix(server): tokens of deleted accounts are refused; a failing message or fight can no longer crash the server

After a database reset an old (still signed) token made economy.load insert a save for a missing user;
the FOREIGN KEY error escaped the WebSocket handler and took the process down in a restart loop.
This commit is contained in:
Benjamin Oezcan
2026-11-19 10:02:51 +01:00
parent 0ffa221e82
commit 3dc770e34a
4 changed files with 34 additions and 5 deletions

View File

@@ -63,8 +63,12 @@ function refresh(refreshToken) {
}
function logout(refreshToken) { if (refreshToken) Tokens.del.run(String(refreshToken)); }
// a token only counts while its account exists (deleted account / database reset -> the client must log in again)
function verify(token) {
try { const d = jwt.verify(String(token || ''), SECRET); return { uid: d.uid, name: d.name, guest: !!d.guest, admin: d.role === 'admin' }; } catch (e) { return null; }
let d;
try { d = jwt.verify(String(token || ''), SECRET); } catch (e) { return null; }
const u = Users.byId.get(d.uid);
return u ? { uid: u.uid, name: u.name, guest: !!u.guest, admin: u.role === 'admin' } : null;
}
// express middleware: Authorization: Bearer <idToken> (or ?auth= for old clients) -> req.user / req.uid
function middleware(req, _res, next) {