mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-09 12:27:43 +00:00
docs: replace with better-fetch and maxDuration for the vercel runtime (#4997)
This commit is contained in:
committed by
GitHub
parent
2d64fe38aa
commit
702da7f790
@@ -1,6 +1,6 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
export const maxDuration = 300;
|
||||||
export async function POST(request: NextRequest) {
|
export async function POST(request: Request) {
|
||||||
try {
|
try {
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const gurubasePayload = {
|
const gurubasePayload = {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|||||||
import Link from "fumadocs-core/link";
|
import Link from "fumadocs-core/link";
|
||||||
import { Markdown } from "./markdown";
|
import { Markdown } from "./markdown";
|
||||||
import { Presence } from "@radix-ui/react-presence";
|
import { Presence } from "@radix-ui/react-presence";
|
||||||
|
import { betterFetch } from "@better-fetch/fetch";
|
||||||
|
|
||||||
const Context = createContext<{
|
const Context = createContext<{
|
||||||
open: boolean;
|
open: boolean;
|
||||||
@@ -81,7 +82,7 @@ function SearchAIInput(props: ComponentProps<"form">) {
|
|||||||
placeholder={isLoading ? "AI is answering..." : "Ask AI"}
|
placeholder={isLoading ? "AI is answering..." : "Ask AI"}
|
||||||
autoFocus
|
autoFocus
|
||||||
className="p-4"
|
className="p-4"
|
||||||
disabled={status === "streaming" || status === "submitted"}
|
disabled={isLoading}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setInput(e.target.value);
|
setInput(e.target.value);
|
||||||
}}
|
}}
|
||||||
@@ -321,7 +322,14 @@ export function AISearchTrigger() {
|
|||||||
requestBody.session_id = sessionId;
|
requestBody.session_id = sessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch("/api/ai-chat", {
|
const { data, error } = await betterFetch<{
|
||||||
|
content?: string;
|
||||||
|
answer?: string;
|
||||||
|
response?: string;
|
||||||
|
session_id?: string;
|
||||||
|
references?: Array<{ link: string; title: string; icon?: string }>;
|
||||||
|
error?: string;
|
||||||
|
}>("/api/ai-chat", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -329,16 +337,12 @@ export function AISearchTrigger() {
|
|||||||
body: JSON.stringify(requestBody),
|
body: JSON.stringify(requestBody),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (error) {
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
console.error("API Error Response:", error);
|
||||||
|
throw new Error(`HTTP ${error.status}: ${error.message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
console.log("API Response:", data);
|
|
||||||
|
|
||||||
// Extract session_id from response if present
|
|
||||||
if (data.session_id) {
|
if (data.session_id) {
|
||||||
console.log("Received session_id:", data.session_id);
|
|
||||||
setSessionId(data.session_id);
|
setSessionId(data.session_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,6 +352,8 @@ export function AISearchTrigger() {
|
|||||||
responseContent = data.content;
|
responseContent = data.content;
|
||||||
} else if (data.answer) {
|
} else if (data.answer) {
|
||||||
responseContent = data.answer;
|
responseContent = data.answer;
|
||||||
|
} else if (data.response) {
|
||||||
|
responseContent = data.response;
|
||||||
} else if (data.error) {
|
} else if (data.error) {
|
||||||
responseContent = data.error;
|
responseContent = data.error;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user