fix: username was not recorded for logout-s
Massimo Melina committed
Feb 10, 2026 at 00:09 UTC
4ded998402c933ecdcae190e38da61bb2ccae4e4
1 file changed
+2
-1
src/log.ts
+2
-1
@@ -73,6 +73,7 @@ const debounce = _.debounce(cb => cb(), 1000) // with this technique, i'll be ab
73
74
export const logMw: Koa.Middleware = async (ctx, next) => {
75
const now = new Date() // request start
76
+ const userAtStart = getCurrentUsername(ctx)
77
// do it now so it's available for returning plugins
78
ctx.state.completed = Promise.race([ once(ctx.res, 'finish'), once(ctx.res, 'close') ])
79
await next()
@@ -118,7 +119,7 @@ export const logMw: Koa.Middleware = async (ctx, next) => {
119
const format = '%s - %s [%s] "%s %s HTTP/%s" %d %s %s\n' // Apache's Common Log Format
120
const a = now.toString().split(' ') // like nginx, our default log contains the time of log writing
121
const date = a[2]+'/'+a[1]+'/'+a[3]+':'+a[4]+' '+a[5]?.slice(3)
121
- const user = getCurrentUsername(ctx)
122
+ const user = getCurrentUsername(ctx) || userAtStart
123
const length = ctx.state.length ?? ctx.length
124
const uri = ctx.originalUrl
125
const duration = (Date.now() - Number(now)) / 1000