umami/pages/api/accounts/index.js

22 lines
444 B
JavaScript
Raw Normal View History

2022-07-12 23:14:36 +02:00
import { getAccounts } from 'queries';
2020-08-12 07:24:41 +02:00
import { useAuth } from 'lib/middleware';
2022-08-29 05:20:54 +02:00
import { ok, unauthorized, methodNotAllowed } from 'next-basics';
2020-08-12 07:24:41 +02:00
export default async (req, res) => {
await useAuth(req, res);
2020-09-16 22:13:50 +02:00
const { is_admin } = req.auth;
2020-08-12 07:24:41 +02:00
2020-09-16 22:13:50 +02:00
if (!is_admin) {
return unauthorized(res);
}
2020-08-12 07:24:41 +02:00
2020-09-16 22:13:50 +02:00
if (req.method === 'GET') {
const accounts = await getAccounts();
2020-08-12 07:24:41 +02:00
2020-09-16 22:13:50 +02:00
return ok(res, accounts);
2020-08-12 07:24:41 +02:00
}
return methodNotAllowed(res);
};