Handle website delete. Added response helper functions.

This commit is contained in:
Mike Cao 2020-08-07 17:19:42 -07:00
parent 0a411a9ad6
commit c4b75e4aec
31 changed files with 314 additions and 96 deletions

View file

@ -1,18 +1,14 @@
import { getWebsite, getSession, createSession } from 'lib/db';
import { getClientInfo } from 'lib/request';
import { uuid, isValidId, verifyToken } from 'lib/crypto';
import { uuid, isValidId, parseToken } from 'lib/crypto';
export async function verifySession(req) {
const { payload } = req.body;
const { website: website_uuid, hostname, screen, language, session } = payload;
if (!isValidId(website_uuid)) {
throw new Error(`Invalid website: ${website_uuid}`);
}
const token = await parseToken(session);
try {
return await verifyToken(session);
} catch {
if (!token || !isValidId(website_uuid) || token.website_uuid !== website_uuid) {
const { userAgent, browser, os, ip, country, device } = await getClientInfo(req, payload);
if (website_uuid) {
@ -50,4 +46,6 @@ export async function verifySession(req) {
}
}
}
return token;
}