Implement session caching.

This commit is contained in:
Mike Cao committed 2020-10-02 20:33:46 -07:00
1 parent 0b131392fc
commit 3d1dc08491
4 files changed
+31 -11

No files matched your search

+10 -2
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}`);