Fixed share page.

This commit is contained in:
Mike Cao 2022-12-13 11:27:55 -08:00
parent cb4c8accea
commit 4c202741c2
11 changed files with 58 additions and 39 deletions

View file

@ -1,5 +1,4 @@
import { WebsiteActive } from 'lib/types';
import { NextApiRequestQueryBody } from 'lib/types';
import { NextApiRequestQueryBody, WebsiteActive } from 'lib/types';
import { canViewWebsite } from 'lib/auth';
import { useAuth, useCors } from 'lib/middleware';
import { NextApiResponse } from 'next';
@ -17,13 +16,15 @@ export default async (
await useCors(req, res);
await useAuth(req, res);
const {
user: { id: userId },
} = req.auth;
const { id: websiteId } = req.query;
const { user, shareToken } = req.auth;
const userId = user?.id;
const websiteId = req.query.id;
const shared = shareToken?.websiteId === websiteId;
if (req.method === 'GET') {
if (await canViewWebsite(userId, websiteId)) {
const canView = await canViewWebsite(userId, websiteId);
if (!canView && !shared) {
return unauthorized(res);
}