0

I am using next-auth with nextjs edge functions. I am using the edge to stream data.

I have my middleware

export { default } from "next-auth/middleware";

// Limit the middleware to paths starting with `/api/`
export const config = {
  matcher: "/api/:function*",
};

How do I get access to the session object now in the API route?

As I no longer have access to the normal next req, response, instead it's the Fetch API

const handler = async (req: Request): Promise<Response> => {

// Below will fail
const session = await getServerSession(req, res, authOptions);

Any help is appreciated, thanks!

Yilmaz
  • 35,338
  • 10
  • 157
  • 202
caffeinescript
  • 1,365
  • 2
  • 13
  • 27

1 Answers1

0

you are passing wrong args to getServerSession. this is its type

getServerSession<AuthOptions, Session>(...args: GetServerSessionParams<AuthOptions>): Promise<Session | null>

I explained authOptions here: How do I use next auth getServerSession in next js 13 beta server component in app directory

Yilmaz
  • 35,338
  • 10
  • 157
  • 202
  • Thanks for the response, I pulled this from the docs https://next-auth.js.org/getting-started/example#backend---api-route which is my above implementation (working). When I implement it without the req, res I run into another issue which is flagged https://stackoverflow.com/questions/76259396/invariant-method-expects-to-have-requestasyncstorage-none-available – caffeinescript May 23 '23 at 09:13