mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
35 lines
829 B
TypeScript
35 lines
829 B
TypeScript
import { useAuth, useCors } from 'lib/middleware';
|
|
import { NextApiRequestQueryBody } from 'lib/types';
|
|
import { NextApiResponse } from 'next';
|
|
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
|
import { getUserWebsites } from 'queries';
|
|
|
|
export interface UserWebsitesRequestBody {
|
|
name: string;
|
|
domain: string;
|
|
shareId: string;
|
|
}
|
|
|
|
export default async (
|
|
req: NextApiRequestQueryBody<any, UserWebsitesRequestBody>,
|
|
res: NextApiResponse,
|
|
) => {
|
|
await useCors(req, res);
|
|
await useAuth(req, res);
|
|
|
|
const { user } = req.auth;
|
|
const { id: userId } = req.query;
|
|
|
|
if (req.method === 'GET') {
|
|
if (!user.isAdmin && user.id !== userId) {
|
|
return unauthorized(res);
|
|
}
|
|
|
|
const websites = await getUserWebsites(userId);
|
|
|
|
return ok(res, websites);
|
|
}
|
|
|
|
return methodNotAllowed(res);
|
|
};
|