1
0
mirror of https://github.com/kremalicious/umami.git synced 2024-12-25 02:36:20 +01:00
umami/pages/api/accounts.js

22 lines
449 B
JavaScript
Raw Normal View History

2020-08-12 07:24:41 +02:00
import { getAccounts } from 'lib/queries';
import { useAuth } from 'lib/middleware';
import { ok, unauthorized, methodNotAllowed } from 'lib/response';
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);
};