mirror of
https://github.com/umami-software/umami.git
synced 2026-02-19 20:15:41 +01:00
fix: invalid website in cache
This commit is contained in:
parent
bce70c1034
commit
afe559f6ae
1 changed files with 18 additions and 7 deletions
|
|
@ -18,10 +18,16 @@ export async function getSession(req: NextApiRequestCollect): Promise<SessionDat
|
||||||
const cacheToken = req.headers['x-umami-cache'];
|
const cacheToken = req.headers['x-umami-cache'];
|
||||||
|
|
||||||
if (cacheToken) {
|
if (cacheToken) {
|
||||||
const result = await parseToken(cacheToken, secret());
|
const result: SessionData | undefined = await parseToken(cacheToken, secret());
|
||||||
|
|
||||||
// Token is valid
|
// Token is valid
|
||||||
if (result) {
|
if (result) {
|
||||||
|
// website may differ in payload
|
||||||
|
if (result.websiteId !== payload.website) {
|
||||||
|
await checkWebsite(payload.website);
|
||||||
|
result.websiteId = payload.website;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -29,12 +35,8 @@ export async function getSession(req: NextApiRequestCollect): Promise<SessionDat
|
||||||
// Verify payload
|
// Verify payload
|
||||||
const { website: websiteId, hostname, screen, language } = payload;
|
const { website: websiteId, hostname, screen, language } = payload;
|
||||||
|
|
||||||
// Find website
|
// check website
|
||||||
const website = await fetchWebsite(websiteId);
|
await checkWebsite(websiteId);
|
||||||
|
|
||||||
if (!website) {
|
|
||||||
throw new Error(`Website not found: ${websiteId}.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { userAgent, browser, os, ip, country, subdivision1, subdivision2, city, device } =
|
const { userAgent, browser, os, ip, country, subdivision1, subdivision2, city, device } =
|
||||||
await getClientInfo(req);
|
await getClientInfo(req);
|
||||||
|
|
@ -90,3 +92,12 @@ export async function getSession(req: NextApiRequestCollect): Promise<SessionDat
|
||||||
|
|
||||||
return { ...session, visitId };
|
return { ...session, visitId };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const checkWebsite = async (websiteId: string) => {
|
||||||
|
// Find website
|
||||||
|
const website = await fetchWebsite(websiteId);
|
||||||
|
|
||||||
|
if (!website) {
|
||||||
|
throw new Error(`Website not found: ${websiteId}.`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue