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

23 lines
579 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) {
2022-10-12 06:48:33 +02:00
const { websiteId, websiteUuid } = website;
const token = createToken({ websiteId, websiteUuid }, secret());
2022-10-12 06:48:33 +02:00
return ok(res, { websiteId, websiteUuid, token });
2020-08-15 10:17:15 +02:00
}
return notFound(res);
}
return methodNotAllowed(res);
};