122 lines
3.1 KiB
JavaScript
122 lines
3.1 KiB
JavaScript
import pool from "@/server/db";
|
|
import { PrivyClient } from "@privy-io/server-auth";
|
|
import {
|
|
Breadcrumb,
|
|
BreadcrumbItem,
|
|
BreadcrumbList,
|
|
BreadcrumbPage,
|
|
} from "@/components/ui/breadcrumb";
|
|
import { Separator } from "@/components/ui/separator";
|
|
import {
|
|
SidebarInset,
|
|
SidebarProvider,
|
|
SidebarTrigger,
|
|
} from "@/components/ui/sidebar";
|
|
import { Chat } from "@/components/chat";
|
|
import { SidebarApp } from "@/components/sidebar-app";
|
|
import { checkpointToVercelAI } from "@/server/checkpointToVercelAI";
|
|
|
|
export const getServerSideProps = async ({ req,params }) => {
|
|
const cookieAuthToken = req.cookies["privy-id-token"];
|
|
|
|
if (!cookieAuthToken) {
|
|
return {
|
|
redirect: {
|
|
destination: "/onboarding",
|
|
permanent: false,
|
|
},
|
|
};
|
|
}
|
|
|
|
const PRIVY_APP_ID = process.env.NEXT_PUBLIC_PRIVY_APP_ID;
|
|
const PRIVY_APP_SECRET = process.env.PRIVY_APP_SECRET;
|
|
const client = new PrivyClient(PRIVY_APP_ID, PRIVY_APP_SECRET);
|
|
|
|
try {
|
|
const claims = await client.verifyAuthToken(cookieAuthToken);
|
|
const userId = claims.userId;
|
|
|
|
const dbRes = await pool.query("SELECT userid, publickey, tg_userid, delegated FROM users WHERE userid = $1", [userId]);
|
|
|
|
if (dbRes.rows.length === 0) {
|
|
return {
|
|
redirect: {
|
|
destination: "/onboarding",
|
|
permanent: false,
|
|
},
|
|
};
|
|
}
|
|
|
|
const { delegated } = dbRes.rows[0];
|
|
|
|
if (!delegated) {
|
|
return {
|
|
redirect: {
|
|
destination: "/onboarding",
|
|
permanent: false,
|
|
},
|
|
};
|
|
}
|
|
const { chatid } = params;
|
|
const thread_id = `${userId}-${chatid}`
|
|
|
|
const initialMessages = await checkpointToVercelAI(thread_id)
|
|
// initial messages logic here
|
|
return {
|
|
props: {
|
|
user: dbRes.rows[0],
|
|
thread_id,
|
|
initialMessages
|
|
},
|
|
};
|
|
} catch (error) {
|
|
console.error("Auth verification failed", error);
|
|
return {
|
|
redirect: {
|
|
destination: "/onboarding",
|
|
permanent: false,
|
|
},
|
|
};
|
|
}
|
|
};
|
|
|
|
export default function Page({thread_id, initialMessages}) {
|
|
return (
|
|
<div className="dark">
|
|
<SidebarProvider>
|
|
<SidebarApp />
|
|
<SidebarInset className="flex flex-col h-screen overflow-y-auto">
|
|
<header className="sticky top-0 flex h-14 shrink-0 items-center gap-2 bg-background">
|
|
<div className="flex flex-1 items-center gap-2 px-3">
|
|
<SidebarTrigger />
|
|
<Separator orientation="vertical" className="mr-2 h-4" />
|
|
<Breadcrumb>
|
|
<BreadcrumbList>
|
|
<BreadcrumbItem>
|
|
<BreadcrumbPage className="line-clamp-1">
|
|
Project Management & Task Tracking
|
|
</BreadcrumbPage>
|
|
</BreadcrumbItem>
|
|
</BreadcrumbList>
|
|
</Breadcrumb>
|
|
</div>
|
|
</header>
|
|
<Chat thread_id={thread_id} initialMessages={initialMessages}/>
|
|
</SidebarInset>
|
|
</SidebarProvider>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
|
|
|
|
// export default function ChatPage({ user }) {
|
|
// return (
|
|
// <div>
|
|
// <h1>Welcome to the Chat Page</h1>
|
|
// <p>Wallet: {user.publickey}</p>
|
|
// <p>Delegated: {user.delegated ? "Yes" : "No"}</p>
|
|
// </div>
|
|
// );
|
|
// }
|