Implement session caching.

This commit is contained in:
Mike Cao 2020-10-02 20:33:46 -07:00
parent 0b131392fc
commit 3d1dc08491
4 changed files with 31 additions and 11 deletions

View file

@ -1,6 +1,6 @@
import { getWebsiteByUuid, getSessionByUuid, createSession } from 'lib/queries';
import { getClientInfo } from 'lib/request';
import { uuid, isValidUuid } from 'lib/crypto';
import { uuid, isValidUuid, parseToken } from 'lib/crypto';
export async function getSession(req) {
const { payload } = req.body;
@ -9,7 +9,15 @@ export async function getSession(req) {
throw new Error('Invalid request');
}
const { website: website_uuid, hostname, screen, language } = payload;
const { website: website_uuid, hostname, screen, language, cache } = payload;
if (cache) {
const result = await parseToken(cache);
if (result) {
return result;
}
}
if (!isValidUuid(website_uuid)) {
throw new Error(`Invalid website: ${website_uuid}`);