2022-10-25 19:45:56 +02:00
|
|
|
import { getWebsite } 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') {
|
2022-10-25 19:45:56 +02:00
|
|
|
const website = await getWebsite({ shareId: id });
|
2020-08-15 10:17:15 +02:00
|
|
|
|
|
|
|
if (website) {
|
2022-10-25 04:48:10 +02:00
|
|
|
const { websiteUuid } = website;
|
|
|
|
const data = { id: websiteUuid };
|
|
|
|
const token = createToken(data, secret());
|
2020-09-18 07:52:20 +02:00
|
|
|
|
2022-10-25 04:48:10 +02:00
|
|
|
return ok(res, { ...data, token });
|
2020-08-15 10:17:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return notFound(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
return methodNotAllowed(res);
|
|
|
|
};
|