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) {
|
2020-09-18 07:52:20 +02:00
|
|
|
const websiteId = website.website_id;
|
2022-08-29 05:20:54 +02:00
|
|
|
const token = createToken({ website_id: websiteId }, secret());
|
2020-09-18 07:52:20 +02:00
|
|
|
|
|
|
|
return ok(res, { websiteId, token });
|
2020-08-15 10:17:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return notFound(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
return methodNotAllowed(res);
|
|
|
|
};
|