Merged auth into new parseRequest method.

This commit is contained in:
Mike Cao 2025-01-25 00:19:22 -08:00
parent e51f182403
commit 2d6428172b
39 changed files with 296 additions and 316 deletions

View file

@ -1,7 +1,7 @@
import { z } from 'zod';
import { checkRequest } from 'lib/request';
import { badRequest, unauthorized, json } from 'lib/response';
import { canViewWebsite, checkAuth } from 'lib/auth';
import { parseRequest } from 'lib/request';
import { unauthorized, json } from 'lib/response';
import { canViewWebsite } from 'lib/auth';
import { getSessionDataProperties } from 'queries';
export async function GET(
@ -14,18 +14,16 @@ export async function GET(
propertyName: z.string().optional(),
});
const { query, error } = await checkRequest(request, schema);
const { auth, query, error } = await parseRequest(request, schema);
if (error) {
return badRequest(error);
return error();
}
const { startAt, endAt, propertyName } = query;
const { websiteId } = await params;
const auth = await checkAuth(request);
if (!auth || !(await canViewWebsite(auth, websiteId))) {
if (!(await canViewWebsite(auth, websiteId))) {
return unauthorized();
}