umami/pages/api/websites.js

23 lines
532 B
JavaScript
Raw Normal View History

2020-08-12 07:24:41 +02:00
import { getUserWebsites } from 'lib/queries';
import { useAuth } from 'lib/middleware';
2020-09-11 08:55:29 +02:00
import { ok, methodNotAllowed, unauthorized } from 'lib/response';
2020-08-12 07:24:41 +02:00
export default async (req, res) => {
await useAuth(req, res);
2020-09-11 08:55:29 +02:00
const { user_id, is_admin } = req.auth;
const { userId } = req.query;
2020-08-12 07:24:41 +02:00
if (req.method === 'GET') {
2020-09-11 08:55:29 +02:00
if (userId && !is_admin) {
return unauthorized(res);
}
const websites = await getUserWebsites(+userId || user_id);
2020-08-12 07:24:41 +02:00
return ok(res, websites);
}
return methodNotAllowed(res);
};