Skip to content

Commit

Permalink
adding athorization header
Browse files Browse the repository at this point in the history
  • Loading branch information
PrinceBaghel258025 committed Nov 14, 2023
1 parent f61a32f commit 80c2d42
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/app/api/chatmodel/[chatid]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { env } from "@/app/env.mjs";
export const revalidate = 0; // disable cache

export const maxDuration = 60;
import { auth } from "@clerk/nextjs";
import { cookies } from "next/headers";

export async function POST(
request: Request,
Expand All @@ -28,10 +30,18 @@ export async function POST(
orgId = body.orgId;
const url = request.url;
console.log("this is request url", url);
const { getToken } = await auth();
console.log("ckkoies", cookies());
console.log("token", await getToken());
const cookieStore = cookies();
const cookiesArray = cookieStore.getAll().map((cookie) => {
const cookieName = cookie.name;
const cookieValue = cookie.value;
return [cookieName, cookieValue] as [string, string];
});

// getting main url
const urlArray = url.split("/");
const mainUrl = urlArray.slice(0, 3).join("/");

let id = params.params.chatid as any;
// exceptional case
Expand Down Expand Up @@ -84,6 +94,10 @@ export async function POST(
{
method: "POST",
body: JSON.stringify({ chat: _chat }),
headers: {
Authorization: `Bearer ${await getToken()}`,
},
// headers: [...cookiesArray]
},
);
await db
Expand Down
18 changes: 16 additions & 2 deletions src/app/api/generateTitle/[chatid]/[orgid]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { generateTitle } from "@/utils/apiHelper";
import { env } from "@/app/env.mjs";
import { ChatEntry } from "@/lib/types";
export const revalidate = 0; // disable cache

import { auth } from "@clerk/nextjs";
import { cookies } from "next/headers";
export async function POST(
request: Request,
params: { params: { chatid: string; orgid: string } },
Expand All @@ -15,16 +16,29 @@ export async function POST(
let orgId = params.params.orgid;
const body = await request.json();

const { getToken } = await auth();
console.log("ckkoies", cookies());
console.log("token", await getToken());
const cookieStore = cookies();
const cookiesArray = cookieStore.getAll().map((cookie) => {
const cookieName = cookie.name;
const cookieValue = cookie.value;
return [cookieName, cookieValue] as [string, string];
});

const messages: ChatEntry[] = body.chat;
const url = request.url;
const urlArray = url.split("/");
const mainUrl = urlArray.slice(0, 3).join("/");
const fullResponse = await generateTitle(messages);
fetch(
`https://zeplo.to/https://${urlArray[2]}/api/generateImage/${chatId}/${orgId}?_token=${env.ZEPLO_TOKEN}`,
{
method: "POST",
body: JSON.stringify({ chatTitle: fullResponse }),
headers: {
Authorization: `Bearer ${await getToken()}`,
},
// headers: cookiesArray
},
);
await db
Expand Down

0 comments on commit 80c2d42

Please sign in to comment.