fix(app/web): clean session token when expired (closes #1204)
This commit is contained in:
@@ -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("/.version", limiter, (req, res) => res.status(200).send(conf.package.version))
|
||||||
app.get("/.requests", limiter, async (req, res) => {
|
app.get("/.requests", limiter, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const custom = uapi(req.headers["x-metrics-session"])
|
const session = req.headers["x-metrics-session"]
|
||||||
|
const custom = uapi(session)
|
||||||
if (custom) {
|
if (custom) {
|
||||||
|
try {
|
||||||
const {data: {resources}} = await custom.rest.rateLimit.get()
|
const {data: {resources}} = await custom.rest.rateLimit.get()
|
||||||
if (resources)
|
if (resources)
|
||||||
return res.status(200).json({rest: resources.core, graphql: resources.graphql, search: resources.search, login: custom.login})
|
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
|
catch {} //eslint-disable-line no-empty
|
||||||
|
|||||||
@@ -17,6 +17,10 @@
|
|||||||
(async () => {
|
(async () => {
|
||||||
const {data: requests} = await axios.get("/.requests")
|
const {data: requests} = await axios.get("/.requests")
|
||||||
this.requests = requests
|
this.requests = requests
|
||||||
|
if (!requests.login) {
|
||||||
|
localStorage.removeItem("session.metrics")
|
||||||
|
delete axios.defaults.headers.common["x-metrics-session"]
|
||||||
|
}
|
||||||
})(),
|
})(),
|
||||||
//Version
|
//Version
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|||||||
@@ -22,6 +22,10 @@
|
|||||||
(async () => {
|
(async () => {
|
||||||
const {data: requests} = await axios.get("/.requests")
|
const {data: requests} = await axios.get("/.requests")
|
||||||
this.requests = requests
|
this.requests = requests
|
||||||
|
if (!requests.login) {
|
||||||
|
localStorage.removeItem("session.metrics")
|
||||||
|
delete axios.defaults.headers.common["x-metrics-session"]
|
||||||
|
}
|
||||||
})(),
|
})(),
|
||||||
//Templates
|
//Templates
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|||||||
@@ -35,6 +35,10 @@
|
|||||||
(async () => {
|
(async () => {
|
||||||
const {data: requests} = await axios.get("/.requests")
|
const {data: requests} = await axios.get("/.requests")
|
||||||
this.requests = requests
|
this.requests = requests
|
||||||
|
if (!requests.login) {
|
||||||
|
localStorage.removeItem("session.metrics")
|
||||||
|
delete axios.defaults.headers.common["x-metrics-session"]
|
||||||
|
}
|
||||||
})(),
|
})(),
|
||||||
//Version
|
//Version
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|||||||
@@ -19,6 +19,10 @@
|
|||||||
(async () => {
|
(async () => {
|
||||||
const {data: requests} = await axios.get("/.requests")
|
const {data: requests} = await axios.get("/.requests")
|
||||||
this.requests = requests
|
this.requests = requests
|
||||||
|
if (!requests.login) {
|
||||||
|
localStorage.removeItem("session.metrics")
|
||||||
|
delete axios.defaults.headers.common["x-metrics-session"]
|
||||||
|
}
|
||||||
})(),
|
})(),
|
||||||
//Version
|
//Version
|
||||||
(async () => {
|
(async () => {
|
||||||
@@ -79,7 +83,7 @@
|
|||||||
const storage = window.localStorage
|
const storage = window.localStorage
|
||||||
const test = "__storage_test__"
|
const test = "__storage_test__"
|
||||||
storage.setItem(test, test)
|
storage.setItem(test, test)
|
||||||
if (localStorage.getItem(test) !== test)
|
if (storage.getItem(test) !== test)
|
||||||
throw new Error("localStorage value mismatch")
|
throw new Error("localStorage value mismatch")
|
||||||
storage.removeItem(test)
|
storage.removeItem(test)
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user