2022-10-25 17:45:56 +00:00
|
|
|
import { getWebsite } from 'queries';
|
2022-08-29 03:20:54 +00:00
|
|
|
import { ok, notFound, methodNotAllowed, createToken } from 'next-basics';
|
|
|
|
|
import { secret } from 'lib/crypto';
|
2020-08-15 08:17:15 +00:00
|
|
|
|
|
|
|
|
export default async (req, res) => {
|
2022-11-01 06:42:37 +00:00
|
|
|
const { id: shareId } = req.query;
|
2020-08-15 08:17:15 +00:00
|
|
|
|
|
|
|
|
if (req.method === 'GET') {
|
2022-11-01 06:42:37 +00:00
|
|
|
const website = await getWebsite({ shareId });
|
2020-08-15 08:17:15 +00:00
|
|
|
|
|
|
|
|
if (website) {
|
2022-11-01 06:42:37 +00:00
|
|
|
const { id } = website;
|
|
|
|
|
const data = { id };
|
2022-10-25 02:48:10 +00:00
|
|
|
const token = createToken(data, secret());
|
2020-09-18 05:52:20 +00:00
|
|
|
|
2022-10-25 02:48:10 +00:00
|
|
|
return ok(res, { ...data, token });
|
2020-08-15 08:17:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return notFound(res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return methodNotAllowed(res);
|
|
|
|
|
};
|