feat(session): create website on session request

This commit is contained in:
SinaniG 2020-11-05 10:33:12 +03:00
parent c881751e4f
commit 66f2075f37
6 changed files with 17137 additions and 8 deletions

View file

@ -1,4 +1,4 @@
import { getWebsiteByUuid, getSessionByUuid, createSession } from 'lib/queries';
import { getWebsiteByUuid, getSessionByUuid, createSession, createWebsite } from 'lib/queries';
import { getClientInfo } from 'lib/request';
import { uuid, isValidUuid, parseToken } from 'lib/crypto';
@ -25,10 +25,17 @@ export async function getSession(req) {
const { userAgent, browser, os, ip, country, device } = await getClientInfo(req, payload);
const website = await getWebsiteByUuid(website_uuid);
let website = await getWebsiteByUuid(website_uuid);
if (!website) {
throw new Error(`Website not found: ${website_uuid}`);
// throw new Error(`Website not found: ${website_uuid}`);
const user_id = 1;
website = await createWebsite(user_id, {
website_uuid,
name: website_uuid,
domain: `http://${website_uuid}`,
share_id: null,
});
}
const { website_id } = website;