Refactor API authentication.

This commit is contained in:
Mike Cao 2022-10-12 13:11:44 -07:00
parent c33729e185
commit 5a4fc96ebc
13 changed files with 71 additions and 73 deletions

View file

@ -1,6 +1,6 @@
import { allowQuery } from 'lib/auth';
import { FILTER_IGNORED } from 'lib/constants';
import { useCors } from 'lib/middleware';
import { useAuth, useCors } from 'lib/middleware';
import { badRequest, methodNotAllowed, ok, unauthorized } from 'next-basics';
import { getPageviewMetrics, getSessionMetrics, getWebsiteByUuid } from 'queries';
@ -34,9 +34,10 @@ function getColumn(type) {
}
export default async (req, res) => {
if (req.method === 'GET') {
await useCors(req, res);
await useCors(req, res);
await useAuth(req, res);
if (req.method === 'GET') {
if (!(await allowQuery(req))) {
return unauthorized(res);
}