umami/src/app/api/share/[shareId]/route.ts
2025-02-05 15:59:59 -08:00

19 lines
536 B
TypeScript

import { json, notFound } from '@/lib/response';
import { createToken } from '@/lib/jwt';
import { secret } from '@/lib/crypto';
import { getSharedWebsite } from '@/queries';
export async function GET(request: Request, { params }: { params: Promise<{ shareId: string }> }) {
const { shareId } = await params;
const website = await getSharedWebsite(shareId);
if (!website) {
return notFound();
}
const data = { websiteId: website.id };
const token = createToken(data, secret());
return json({ ...data, token });
}