NextRequest types are wrong after nextjs v12.2.0
Question 💬
On the left are the new types from NextJS and on the Right are the types that getToken are using. When upgrading NextJS passed 12.2.0 the types become incompatible.
This is the type of error when upgrading to NextJS v12.2.5
I believe the fix would be upgrading the nextJS package and making sure the types are updated. I'm more than happy to help out with this if I can be pointed in the right direction for how to get started :)
How to reproduce ☕️
import { getToken } from 'next-auth/jwt';
import { NextResponse, NextRequest } from 'next/server';
export const middleware = async (req: NextRequest) => {
const token = await getToken({
req, // Type error here
secret: process.env.JWT_SECRET,
secureCookie: secureCookie(),
});
...
return NextResponse.next();
};
Contributing 🙌🏽
Yes, I am willing to help answer this question in a PR
I believe bumping next to 12.2.5 in devDependencies should fix it. Feels a bit weird that a devDependencies causes this, so in addition, I think we need same version of next in peerDependencies too 🤔 PR welcomes!
Closed in #5384
Cannot use Next.js 12.3.1 with the latest Next-Auth package version anymore.
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: @accelist/[email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/next
npm ERR! next@"12.3.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer next@"12.2.5" from [email protected]
npm ERR! node_modules/next-auth
npm ERR! next-auth@"4.12.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!