From 66d7a815fcabcf68fa61e54dd83d10b257196f58 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Sun, 3 Dec 2023 22:49:30 -0800 Subject: [PATCH] Fixed websites query. --- src/lib/auth.ts | 2 +- src/lib/crypto.ts | 2 +- src/pages/api/websites/index.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/auth.ts b/src/lib/auth.ts index 97e20d98..cb3d3cc7 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -59,7 +59,7 @@ export async function canViewWebsite({ user, shareToken }: Auth, websiteId: stri return !!(await findTeamWebsiteByUserId(websiteId, user.id)); } -export async function canViewAllWebsite({ user }: Auth) { +export async function canViewAllWebsites({ user }: Auth) { return user.isAdmin; } diff --git a/src/lib/crypto.ts b/src/lib/crypto.ts index b0ce20de..a2763352 100644 --- a/src/lib/crypto.ts +++ b/src/lib/crypto.ts @@ -12,7 +12,7 @@ export function salt() { return hash(secret(), ROTATING_SALT); } -export function uuid(...args: [any]) { +export function uuid(...args: any) { if (!args.length) return v4(); return v5(hash(...args, salt()), v5.DNS); diff --git a/src/pages/api/websites/index.ts b/src/pages/api/websites/index.ts index 099649fa..02ec713b 100644 --- a/src/pages/api/websites/index.ts +++ b/src/pages/api/websites/index.ts @@ -1,4 +1,4 @@ -import { canCreateWebsite, canViewAllWebsite } from 'lib/auth'; +import { canCreateWebsite, canViewAllWebsites } from 'lib/auth'; import { uuid } from 'lib/crypto'; import { useAuth, useCors, useValidate } from 'lib/middleware'; import { NextApiRequestQueryBody, SearchFilter } from 'lib/types'; @@ -41,7 +41,7 @@ export default async ( } = req.auth; if (req.method === 'GET') { - if (canViewAllWebsite(req.auth)) { + if (await canViewAllWebsites(req.auth)) { const websites = getWebsites(req.query, { include: { teamWebsite: {