Skip to content

Use pub token auth for ManagePrompt #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions apps/web/pages/api/ai/mp-auth-webhook.ts

This file was deleted.

11 changes: 7 additions & 4 deletions apps/web/pages/free-tools/ai-changelog-generator.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<typeof getStaticProps>) {
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
const theme = usePrefersColorScheme();

const [content, setContent] = useState("");
Expand Down Expand Up @@ -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}`,
},
};
}
18 changes: 18 additions & 0 deletions apps/web/utils/manageprompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,21 @@ export async function runWorkflow(

return result;
}

export async function getPubToken(): Promise<string> {
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;
}