diff --git a/source/app/web/instance.mjs b/source/app/web/instance.mjs index 22c839c3..eb448f31 100644 --- a/source/app/web/instance.mjs +++ b/source/app/web/instance.mjs @@ -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 diff --git a/source/app/web/statics/app.js b/source/app/web/statics/app.js index 930674c5..381a76ba 100644 --- a/source/app/web/statics/app.js +++ b/source/app/web/statics/app.js @@ -17,6 +17,10 @@ (async () => { const {data: requests} = await axios.get("/.requests") this.requests = requests + if (!requests.login) { + localStorage.removeItem("session.metrics") + delete axios.defaults.headers.common["x-metrics-session"] + } })(), //Version (async () => { diff --git a/source/app/web/statics/embed/app.js b/source/app/web/statics/embed/app.js index 75151393..aaacc433 100644 --- a/source/app/web/statics/embed/app.js +++ b/source/app/web/statics/embed/app.js @@ -22,6 +22,10 @@ (async () => { const {data: requests} = await axios.get("/.requests") this.requests = requests + if (!requests.login) { + localStorage.removeItem("session.metrics") + delete axios.defaults.headers.common["x-metrics-session"] + } })(), //Templates (async () => { diff --git a/source/app/web/statics/insights/script.js b/source/app/web/statics/insights/script.js index a265d66c..cfd1775a 100644 --- a/source/app/web/statics/insights/script.js +++ b/source/app/web/statics/insights/script.js @@ -35,6 +35,10 @@ (async () => { const {data: requests} = await axios.get("/.requests") this.requests = requests + if (!requests.login) { + localStorage.removeItem("session.metrics") + delete axios.defaults.headers.common["x-metrics-session"] + } })(), //Version (async () => { diff --git a/source/app/web/statics/oauth/script.js b/source/app/web/statics/oauth/script.js index 24250809..20816b7f 100644 --- a/source/app/web/statics/oauth/script.js +++ b/source/app/web/statics/oauth/script.js @@ -19,6 +19,10 @@ (async () => { const {data: requests} = await axios.get("/.requests") this.requests = requests + if (!requests.login) { + localStorage.removeItem("session.metrics") + delete axios.defaults.headers.common["x-metrics-session"] + } })(), //Version (async () => { @@ -79,7 +83,7 @@ const storage = window.localStorage const test = "__storage_test__" storage.setItem(test, test) - if (localStorage.getItem(test) !== test) + if (storage.getItem(test) !== test) throw new Error("localStorage value mismatch") storage.removeItem(test) return true