Skip to content

Type conflicts between NextAuth and Next.js Route Handlers #8243

Closed
@Lada496

Description

@Lada496

Question 💬

I'm having type errors while trying to implement Advanced initialization with Route Handlers[https://nextjs.org/docs/app/building-your-application/routing/route-handlers] and wondering if there is any solution to fix this issue.

Error Messages:

  • Type '{ __tag__: "GET"; __param_position__: "first"; __param_type__: NextApiRequest; }' does not satisfy the constraint 'ParamCheck<Request | NextRequest>'.
  • Type '{ __tag__: "POST"; __param_position__: "first"; __param_type__: NextApiRequest; }' does not satisfy the constraint 'ParamCheck<Request | NextRequest>'.
  • Types of property '__param_type__' are incompatible.
  • Type 'NextApiRequest' is not assignable to type 'Request | NextRequest'.
  • Type 'NextApiRequest' is missing the following properties from type 'NextRequest': geo, ip, nextUrl, page, and 19 more.

Code

import type { NextApiRequest, NextApiResponse } from "next";
import { cookies } from "next/headers";
import NextAuth from "next-auth";
import { authOptions } from "~/server/auth";

async function auth(req: NextApiRequest, res: NextApiResponse) {
 ...some logic
  return await NextAuth(req, res, authOptions);
}

export { auth as GET, auth as POST };

In contrary when I use Request instead of NextApiRequest, then I get another type error: Type 'Request' is missing the following properties from type 'NextApiRequest': query, cookies, env, aborted, and 53 more.

How to reproduce ☕️

  • Next.js v13.4.1
  • NextAuth.js v4.21.0

While code is available here

Contributing 🙌🏽

Yes, I am willing to help answer this question in a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAsk how to do something or how something works

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions