umami/pages/api/share/[id].js

23 lines
559 B
JavaScript
Raw Normal View History

2022-07-12 23:14:36 +02:00
import { getWebsiteByShareId } from 'queries';
2022-08-29 05:20:54 +02:00
import { ok, notFound, methodNotAllowed, createToken } from 'next-basics';
import { secret } from 'lib/crypto';
2020-08-15 10:17:15 +02:00
export default async (req, res) => {
const { id } = req.query;
if (req.method === 'GET') {
const website = await getWebsiteByShareId(id);
if (website) {
const websiteId = website.website_id;
2022-08-29 05:20:54 +02:00
const token = createToken({ website_id: websiteId }, secret());
return ok(res, { websiteId, token });
2020-08-15 10:17:15 +02:00
}
return notFound(res);
}
return methodNotAllowed(res);
};