-
Notifications
You must be signed in to change notification settings - Fork 389
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
Cannot use type on app router API route handler request: Request
#1467
Comments
Hi @michaeloliverx - thanks for raising this The What's the problem with you using |
Thanks for the fast response!
I wonder if the SDK used the import { cookies } from 'next/headers'
...
const cookieStore = cookies()
Nothing really I just wasn't aware what the problem was and usually I prefer to use the native I guess a note in the docs might help others as well? |
Even if the SDK didn't use
I don't think a special callout is required for this SDK just accurately typing a Next api route |
I totally get what you are saying and using The cookies and headers docs show examples for both Also if you look at the streaming section on the same page, that example returns a /**
* A utility class for streaming text responses.
*/
declare class StreamingTextResponse extends Response {
constructor(res: ReadableStream, init?: ResponseInit, data?: experimental_StreamData);
} I am personally using the Vercel AI SDK (https://github.com/vercel/ai) so after changing the request type to import { withApiAuthRequired } from "@auth0/nextjs-auth0/edge";
import OpenAI from "openai";
import { type NextRequest } from "next/server";
import { OpenAIStream, StreamingTextResponse } from "ai";
export const runtime = "edge";
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
export const GET = withApiAuthRequired(async (request: NextRequest) => {
const { messages } = await request.json();
const response = await openai.chat.completions.create({
model: "gpt-4-0613",
stream: true,
messages: [...messages],
});
const stream = OpenAIStream(response, {});
return new StreamingTextResponse(stream, {});
}); TS output:
From a user and DX perspective it would be a great win if it just worked with the |
I still think
You are correct, the function you pass to
Can you confirm if your code snippet you've shared actually works? (if you ignore the type error) I haven't tested this with a |
The snippet I shared isn't the exact code I am running as I stripped out all the logic.. BUT it does seem to work yes! Hitting it without auth gives me a 401 with {
"error": "not_authenticated",
"description": "The user does not have an active session or is not authenticated",
}
And hitting it with does stream the text fine. |
Great - thanks for confirming @michaeloliverx Will follow up with a PR shortly |
Checklist
Description
Next.js 13 supports using
Request
andResponse
types, Auth0 SDK complains about types.Reproduction
Additional context
No response
nextjs-auth0 version
3.1.0
Next.js version
13.5.3
Node.js version
16.19.1
The text was updated successfully, but these errors were encountered: