Implement session caching.
This commit is contained in:
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user