fix(app/web): clean session token when expired (closes #1204)

This commit is contained in:
lowlighter
2022-08-28 14:07:08 -04:00
parent fad6332133
commit 1515c67977
5 changed files with 27 additions and 2 deletions

View File

@@ -176,11 +176,20 @@ export default async function({sandbox = false} = {}) {
app.get("/.version", limiter, (req, res) => res.status(200).send(conf.package.version))
app.get("/.requests", limiter, async (req, res) => {
try {
const custom = uapi(req.headers["x-metrics-session"])
const session = req.headers["x-metrics-session"]
const custom = uapi(session)
if (custom) {
try {
const {data: {resources}} = await custom.rest.rateLimit.get()
if (resources)
return res.status(200).json({rest: resources.core, graphql: resources.graphql, search: resources.search, login: custom.login})
} catch (error) {
if (error.status === 401) {
console.debug(`metrics/app/oauth > session ${session.substring(0, 6)} is not valid anymore, removing it from cache`)
authenticated.delete(session)
}
throw error
}
}
}
catch {} //eslint-disable-line no-empty