diff --git a/apps/web/pages/api/ai/mp-auth-webhook.ts b/apps/web/pages/api/ai/mp-auth-webhook.ts deleted file mode 100644 index 7a76328..0000000 --- a/apps/web/pages/api/ai/mp-auth-webhook.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { IErrorResponse } from "@changes-page/supabase/types/api"; -import type { NextApiRequest, NextApiResponse } from "next"; - -const managePromptAuthWebhook = async ( - req: NextApiRequest, - res: NextApiResponse<{ success: boolean; ttl: number } | IErrorResponse> -) => { - if (req.method === "POST") { - const { workflowId } = req.body; - - if (workflowId === process.env.MANAGEPROMPT_CHANGEGPT_WORKFLOW_ID) { - res.status(200).json({ success: true, ttl: 86400 }); - return; - } - - res.status(401).json({ - error: { - statusCode: 401, - message: "Invalid workflowId", - }, - }); - } else { - res.setHeader("Allow", "POST"); - res.status(405).end("Method Not Allowed"); - } -}; - -export default managePromptAuthWebhook; diff --git a/apps/web/pages/free-tools/ai-changelog-generator.tsx b/apps/web/pages/free-tools/ai-changelog-generator.tsx index e4525bc..0cd013d 100644 --- a/apps/web/pages/free-tools/ai-changelog-generator.tsx +++ b/apps/web/pages/free-tools/ai-changelog-generator.tsx @@ -1,7 +1,7 @@ import { SpinnerWithSpacing } from "@changes-page/ui"; import { LightningBoltIcon, RefreshIcon } from "@heroicons/react/solid"; import classNames from "classnames"; -import { InferGetStaticPropsType } from "next"; +import { InferGetServerSidePropsType } from "next"; import { useCallback, useState } from "react"; import { createToastWrapper, @@ -12,12 +12,13 @@ import FooterComponent from "../../components/layout/footer.component"; import MarketingHeaderComponent from "../../components/marketing/marketing-header.component"; import { track } from "../../utils/analytics"; import usePrefersColorScheme from "../../utils/hooks/usePrefersColorScheme"; +import { getPubToken } from "../../utils/manageprompt"; export default function AIChangelogGenerator({ title, description, modelStreamUrl, -}: InferGetStaticPropsType) { +}: InferGetServerSidePropsType) { const theme = usePrefersColorScheme(); const [content, setContent] = useState(""); @@ -297,13 +298,15 @@ export default function AIChangelogGenerator({ ); } -export async function getStaticProps() { +export async function getServerSideProps() { + const token = await getPubToken(); + return { props: { title: "ChangeCraftAI: Free Changelog Generator", description: "Say goodbye to the tedious task of writing changelog and release notes. Our revolutionary tool powered by GPT-3 automatically generates them for you, and it's completely free!", - modelStreamUrl: `https://manageprompt.com/api/v1/run/${process.env.MANAGEPROMPT_CHANGEGPT_WORKFLOW_ID}/stream`, + modelStreamUrl: `https://manageprompt.com/api/v1/run/${process.env.MANAGEPROMPT_CHANGEGPT_WORKFLOW_ID}/stream?token=${token}`, }, }; } diff --git a/apps/web/utils/manageprompt.ts b/apps/web/utils/manageprompt.ts index 727bd34..74822fc 100644 --- a/apps/web/utils/manageprompt.ts +++ b/apps/web/utils/manageprompt.ts @@ -20,3 +20,21 @@ export async function runWorkflow( return result; } + +export async function getPubToken(): Promise { + const { token, success } = await fetch( + `https://manageprompt.com/api/v1/token`, + { + method: "GET", + headers: { + Authorization: `Bearer ${process.env.MANAGEPROMPT_SECRET}`, + }, + } + ).then((response) => response.json()); + + if (!success) { + throw new Error("Failed to get token"); + } + + return token; +}