2023-02-08 01:29:25 +01:00
|
|
|
import { useAuth, useCors } from 'lib/middleware';
|
|
|
|
import { NextApiRequestQueryBody } from 'lib/types';
|
|
|
|
import { NextApiResponse } from 'next';
|
|
|
|
import { methodNotAllowed, ok } from 'next-basics';
|
|
|
|
import { getUserWebsites } from 'queries';
|
|
|
|
|
2023-05-23 00:38:03 +02:00
|
|
|
export default async (req: NextApiRequestQueryBody, res: NextApiResponse) => {
|
2023-02-08 01:29:25 +01:00
|
|
|
await useCors(req, res);
|
|
|
|
await useAuth(req, res);
|
|
|
|
|
|
|
|
const {
|
|
|
|
user: { id: userId },
|
|
|
|
} = req.auth;
|
|
|
|
|
|
|
|
if (req.method === 'GET') {
|
|
|
|
const websites = await getUserWebsites(userId);
|
|
|
|
|
|
|
|
return ok(res, websites);
|
|
|
|
}
|
|
|
|
|
|
|
|
return methodNotAllowed(res);
|
|
|
|
};
|