Fix api-tokens date display + quiet authIO no-token log (#120)
- api_tokens.ejs: created_on/last_used_on come back from Redis as strings
(model-redis only coerces fields with an explicit `type`), so `new Date(ms)`
yielded "Invalid date". Use `moment(ms, "x")` (the hosts.ejs/dns.ejs
precedent) which parses a numeric string-or-number as a Unix-ms timestamp.
- api_tokens.ejs: `isExpired` is a class getter not serialized to the client
JSON, so the "expired" badge never showed — compute expiry in the view via
`Date.now() > Number(expires_at)`. Also guard the `last_used_on: 0` / falsy
case (string "0" is truthy) so unset timestamps render "—" not "1970".
- middleware/auth.js: authIO did `checkToken(socket.handshake.auth.token || 0)`,
so any socket connect without a token (login page, pre-login) did an
`AuthToken.get(0)` lookup and logged a noisy `EntryNotFound` trace. Guard:
reject the socket with a generic 401 when there's no token (behavior-
preserving — unauth sockets were already rejected; just no Redis lookup / 404).
- dns_provider.js: drop a stray `console.log('currentDomains:', ...)` debug
line in updateDomains() (unrelated, noticed while investigating).
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -37,7 +37,12 @@ async function auth(req, res, next){
|
||||
|
||||
async function authIO(socket, next){
|
||||
try{
|
||||
let token = await Auth.checkToken(socket.handshake.auth.token || 0);
|
||||
// No token in the handshake (e.g. a page hit before login, or a socket
|
||||
// opened while logged out) → reject the socket cleanly without doing an
|
||||
// AuthToken.get(0) lookup that throws a noisy EntryNotFound trace.
|
||||
let tok = socket.handshake.auth && socket.handshake.auth.token;
|
||||
if(!tok) return next(Auth.errors.login());
|
||||
let token = await Auth.checkToken(tok);
|
||||
socket.user = token.user;
|
||||
next();
|
||||
}catch(error){
|
||||
|
||||
@@ -200,7 +200,6 @@ class DnsProvider extends Table{
|
||||
...(domain.zoneId !== undefined ? {zoneId: domain.zoneId} : {}),
|
||||
});
|
||||
}
|
||||
console.log('currentDomains:', currentDomains)
|
||||
|
||||
for(let domain of currentDomains){
|
||||
if(!domain) continue
|
||||
|
||||
@@ -43,13 +43,21 @@
|
||||
}
|
||||
|
||||
function fmtTime(ms){
|
||||
if(!ms) return '—';
|
||||
return moment(new Date(ms)).fromNow() + ' <span class="text-muted">(' + moment(new Date(ms)).format('YYYY-MM-DD HH:mm') + ')</span>';
|
||||
// created_on/last_used_on come back from Redis as strings (model-redis
|
||||
// only coerces fields with an explicit `type`); moment(value, "x") parses
|
||||
// a numeric string-or-number as a Unix-ms timestamp, unlike new Date(str).
|
||||
if(!ms || Number(ms) === 0) return '—';
|
||||
var t = moment(ms, "x");
|
||||
if(!t.isValid()) return '—';
|
||||
return t.fromNow() + ' <span class="text-muted">(' + t.format('YYYY-MM-DD HH:mm') + ')</span>';
|
||||
}
|
||||
function fmtExpiry(token){
|
||||
if(!token.expires_at) return '<span class="badge text-bg-secondary">never</span>';
|
||||
if(token.isExpired) return '<span class="badge text-bg-danger">expired</span>';
|
||||
return '<span class="badge text-bg-warning text-dark">' + moment(new Date(token.expires_at)).fromNow() + '</span>';
|
||||
// expires_at is type:number (a real number); isExpired is a class getter
|
||||
// that is NOT serialized to the client, so compute expiry here.
|
||||
var exp = Number(token.expires_at);
|
||||
if(!exp) return '<span class="badge text-bg-secondary">never</span>';
|
||||
if(Date.now() > exp) return '<span class="badge text-bg-danger">expired</span>';
|
||||
return '<span class="badge text-bg-warning text-dark">' + moment(exp, "x").fromNow() + '</span>';
|
||||
}
|
||||
|
||||
function processToken(token){
|
||||
|
||||
Reference in New Issue
Block a user